$('#changId).change(function(){
$.ajax({
type: 'POST',
data:"id="+$('#id).val(),
url: 'whms.html?method=getType',
success: function(json){
var jsont = eval(json);
var row = "<option value='-1'>Please Select</option>";
$('#selectId').append(row);
$('# selectId').append(row);
for(i=0;i<jsont.length;i++){
json=jsont[i];
var id=json[0];
var name=json[1];
var row = "<option value="+id+">"+name+"</option>";
$('# selectId').append(row);
}
},
error:function(data){
alert("error!");
}
})
});
//这里是控制器的部分
@RequestMapping(params = " method=getType")
public void getType (Model model, HttpServletRequest request, HttpServletResponse response) throws IOException {
Long id = request.getParamater("id");
ArrayList<Object> list = whmsManager.getType(id);
JSONArray json = JSONArray.fromObject(list);
PrintWriter out = null;
out = response.getWriter();
out.print(json.toString());
}
//这里是业务逻辑的部分
public ArrayList<Object> getType (long id) {
ArrayList<Object> al = new ArrayList<Object>();
List<Whms> list = getMaterialType(Id);
for (Type type: list) {
ArrayList<String> innerList = new ArrayList<String>();
innerList.add(type.getId().toString());
innerList.add(type.getName());
innerList.add(type.getWhmsTypeName());
al.add(innerList);
}
return al;
}
注:不能传入一个已经定义好的实体,因为JSONArray.fromObject,所以建议使用dwr