easyui 和jsp虽说是老技术,最近学校期末考核项目,正好用上,记录一下。
后端返回一个嵌套json给表格
{"rows":[
{"id":2,"sno":"55","name":"声","password":"233",
"clazz":{"id":1,"name":"计算机182","dept":"信工","stu_id":2},
"stuInfo":{"id":2,"age":"11","sex":"男","address":"广东茂名","phone":"67","dormitory":"11-325","native_place":"汉族"}
},
{"id":3,"sno":"3","name":"name","password":"r",
"clazz":{"id":2,"name":"计算机182","dept":"信工","stu_id":3},
"stuInfo":{"id":3,"age":"22","sex":"男","address":null,"phone":null,"dormitory":null,"native_place":null}}],
"total":4}
想要加载到表格:
两种方法:
<th field="clazzName" align="center"
data-options="formatter: function(value,row,index){
console.log(row);
if (row.clazz){
row.clazzName = row.clazz.name;
return row.clazzName;
} else {
return value;
}
}">班级</th>
或者
function loadFilter(data){
len = data.rows.length;
for (var i = 0; i < len; i++) {
if(data.rows[i].clazz != undefined){
data.rows[i].clazzName= data.rows[i].clazz.name;
}
}
return data;
}
。。。。