Created
August 15, 2011 05:38
-
-
Save endymuhardin/1145756 to your computer and use it in GitHub Desktop.
Membuat JSON Response untuk dijit.form.FilteringSelect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
identifier:"id", | |
label: "label", | |
items: [ | |
{id:"1", label:"L-001 - Loket 001"}, | |
{id:"2", label:"L-002 - Loket 002"} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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