我正在使用带有 jqgrid 的 spring 3 一切工作正常,除了从控制器将数据加载到选择选项中我尝试加载到 jsion Array 对象并发送到 jsp 页面,但我无法加载值以使用选择选项
(editoptions: {dataUrl:"location/role.do")
请查看我的代码并帮助我
我的控制器类是
@Controller
@RequestMapping("/location")
public class AddCenterLocation {
@Autowired
private RecoupService recoupService;
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody
CustomCenterLocationResponse getAll() {
List<? extends CenterLocation> users = recoupService.getCenter();
response.setRows(users);
response.setRecords(String.valueOf(users.size()));
response.setPage("1");
response.setTotal("10");
return response;
}
@RequestMapping(value = "/role", method = RequestMethod.GET)
public @ResponseBody
CustomGenericResponse role(HttpServletRequest request, HttpServletResponse response) {
JSONObject jsonArray = new JSONObject();
try {
List<CenterLocation> users = recoupService.getCenter();
for (CenterLocation harbour : users) {
jsonArray.put(harbour.getCenterId(), harbour.getCenterAddress());
}
response.getWriter().write(jsonArray.toString());
} catch (Exception exception) {
System.out.println("error is " + exception);
}
return null;
}
这是我的jsp页面
jq(function() {
jq("#grid").jqGrid({
url:'location.do',
datatype: 'json',
mtype: 'GET',
colNames:['Id', 'Center Name', 'Address','Country','State','City','Pin Code','Land Line No','Mobile No','Role'],
colModel:[
{name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true,size:10},hidden:true},
{name:'centerName',index:'centerName', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'centerAddress',index:'centerAddress', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'centerCountry',index:'centerCountry', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'centerState',index:'centerState', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'centerCity',index:'centerCity', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'centerPinCode',index:'centerPinCode', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'landLineNo',index:'landLineNo', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{name:'mobileNo',index:'mobileNo', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}},
{ name: 'Slger', index: 'Slger', editable: true, edittype: "select",
editoptions: {dataUrl:"location/role.do",
buildSelect: function (data) {
var response = jQuery.parseJSON(data.responseText);
var s = '<select>';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var ri = response[i];
s += '<option value="' + ri + '">' + ri + '</option>';
}
}
return s + "</select>";
}
}
}
],
postData: {
},
rowNum:20,
rowList:[20,40,60],
height: 400,
autowidth: true,
rownumbers: true,
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"Users",
emptyrecords: "Empty records",
loadonce: false,
loadComplete: function() {
},
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
}
});
jq("#grid").jqGrid('navGrid','#pager',
{edit:false,add:false,del:false,search:true},
{ },
{ },
{ },
{
sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'],
closeOnEscape: true,
multipleSearch: true,
closeAfterSearch: true }
);
jq("#grid").navButtonAdd('#pager',
{ caption:"Add",
buttonicon:"ui-icon-plus",
onClickButton: addRow,
position: "last",
title:"",
cursor: "pointer"
}
);
jq("#grid").navButtonAdd('#pager',
{ caption:"Edit",
buttonicon:"ui-icon-pencil",
onClickButton: editRow,
position: "last",
title:"",
cursor: "pointer"
}
);
jq("#grid").navButtonAdd('#pager',
{ caption:"Delete",
buttonicon:"ui-icon-trash",
onClickButton: deleteRow,
position: "last",
title:"",
cursor: "pointer"
}
);
jq("#btnFilter").click(function(){
jq("#grid").jqGrid('searchGrid',
{multipleSearch: false,
sopt:['eq']}
);
});
// Toolbar Search
jq("#grid").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch:"cn"});
});