The action returns the JSON format as Follows:
jsonResult = { total=7,rows=[ {TEXT=技术支持, ID=402894ca4419acf1014419b148a10000}, {TEXT=开发部, ID=402894ca4419acf1014419beb1bc0001}, {TEXT=实施, ID=4028e439476b55be01477bbf0fab0000}, {TEXT=技术支持, ID=4028e439476b55be01477bbfb80e0001}, {TEXT=客户服务, ID=4028e439476b55be01477bc015a80002}]}
The JSON contains Total and rows, and we need the contents below the rows to be shown in the combobox, and the API requires JSON in the following format:
[{ "id":1, "text":"text1" },{ "id":2, "text":"text2" },{ "id":3, "text":"text3", "selected":true },{ "id":4, "text":"text4" },{ "id":5, "text":"text5" }]
The official gives an example
$(‘#cc‘).combobox({ url:‘combobox_data.json‘, valueField:‘id‘, textField:‘text‘ });
Never understood. how do I return data with just one url? Miss Bai-no-sis
Here are two workarounds
the First Type:
var url = "admin/FrmQueryAllGroup.do";$.getJSON(url,function(json) { $(‘#cc‘).combobox({ data: json.jsonResult.rows, valueField: ‘ID‘, textField: ‘TEXT‘ });});
the Second Type:
$.ajax({ "POST", url: ‘admin/FrmQueryAllGroup.do‘, dataType: "json", success: function(json) { $(‘#cc‘).combobox({ data: json.jsonResult.rows, valueField: ‘ID‘, textField: ‘TEXT‘ }); }});
注:jsonResult 为Action中返回值,rows 为 jsonResult 中的属性
Struts.xml
<Packagename= "frmtaskuser_ajax_code" extends= "json-default" > << Span class= "hljs-title" >action name= "FrmQueryAllGroup" Span class= "hljs-attribute" >method= "queryallgroup" class=< Span class= "hljs-value" > "org.bkgd.autoform.web.action.ActionTaskuserFormQuery" > << Span class= "hljs-title" >result type= "json" ></result> </action ></package>
Easyui combobox loading JSON data