Skip to content

Instantly share code, notes, and snippets.

@endymuhardin
Created August 15, 2011 05:38
Show Gist options
  • Save endymuhardin/1145756 to your computer and use it in GitHub Desktop.
Save endymuhardin/1145756 to your computer and use it in GitHub Desktop.
Membuat JSON Response untuk dijit.form.FilteringSelect
{
identifier:"id",
label: "label",
items: [
{id:"1", label:"L-001 - Loket 001"},
{id:"2", label:"L-002 - Loket 002"}
]
}
@Controller
public class LoketController {
@RequestMapping("/loket/json")
@ResponseBody
public Map<String, Object> loketJson(){
Loket l = new Loket();
l.setId(100);
l.setKode("L-001");
l.setNama("Loket 001");
// nantinya ini query dari database
List<Loket> hasilQueryDb = new ArrayList<Loket>();
Map<String, Object> hasilAkhir = new HashMap<String, Object>();
hasilAkhir.put("identifier", "id");
hasilAkhir.put("label", "label");
List<Map<String, String>> items = new ArrayList<Map<String, String>>();
for(Loket l : hasilQueryDb){
Map<String, String> data = new HashMap<String, String>();
data.put("id", l.getId().toString());
data.put("label", l.getKode() + " - " +l.getNama());
items.add(data);
}
hasilAkhir.put("items", items);
return hasilAkhir;
}
}
<select name="id_loket">
<option value="1">L-001 - Loket 001</option>
<option value="2">L-002 - Loket 002</option>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment