问题描述
- Easyui dtagrid 绑定数据问题
-
json串如下:
{"total":6,"rows":[{"classes":{"id":11,"name":"123456","students":[{"classes":null,"id":28,"money":100
,"stuAge":"15","stuName":"张三","stuSex":"女"},{"classes":null,"id":25,"money":100,"stuAge":"13","stuName"
:"田七","stuSex":"男"},{"classes":null,"id":24,"money":100,"stuAge":"12","stuName":"赵六","stuSex":"女"},{"classes"
:null,"id":26,"money":100,"stuAge":"14","stuName":"王五","stuSex":"女"},null]},"id":23,"money":300,"stuAge"
:"13","stuName":"李四","stuSex":"男"},{"classes":{"id":11,"name":"123456","students":[{"classes":null,"id"
:28,"money":100,"stuAge":"15","stuName":"张三","stuSex":"女"},{"classes":null,"id":25,"money":100,"stuAge"
:"13","stuName":"田七","stuSex":"男"},null,{"classes":null,"id":26,"money":100,"stuAge":"14","stuName":"
王五","stuSex":"女"},{"classes":null,"id":23,"money":300,"stuAge":"13","stuName":"李四","stuSex":"男"}]},"id"
:24,"money":100,"stuAge":"12","stuName":"赵六","stuSex":"女"},{"classes":{"id":11,"name":"123456","students"
:[{"classes":null,"id":28,"money":100,"stuAge":"15","stuName":"张三","stuSex":"女"},null,{"classes":null
,"id":24,"money":100,"stuAge":"12","stuName":"赵六","stuSex":"女"},{"classes":null,"id":26,"money":100,"stuAge"
:"14","stuName":"王五","stuSex":"女"},{"classes":null,"id":23,"money":300,"stuAge":"13","stuName":"李四","stuSex"
:"男"}]},"id":25,"money":100,"stuAge":"13","stuName":"田七","stuSex":"男"},{"classes":{"id":11,"name":"123456"
,"students":[{"classes":null,"id":28,"money":100,"stuAge":"15","stuName":"张三","stuSex":"女"},{"classes"
:null,"id":25,"money":100,"stuAge":"13","stuName":"田七","stuSex":"男"},{"classes":null,"id":24,"money"
:100,"stuAge":"12","stuName":"赵六","stuSex":"女"},null,{"classes":null,"id":23,"money":300,"stuAge":"13"
,"stuName":"李四","stuSex":"男"}]},"id":26,"money":100,"stuAge":"14","stuName":"王五","stuSex":"女"},{"classes"
:{"id":10,"name":"131311","students":[null]},"id":27,"money":100,"stuAge":"14","stuName":"旺旺","stuSex"
:"男"},{"classes":{"id":11,"name":"123456","students":[null,{"classes":null,"id":25,"money":100,"stuAge"
:"13","stuName":"田七","stuSex":"男"},{"classes":null,"id":24,"money":100,"stuAge":"12","stuName":"赵六","stuSex"
:"女"},{"classes":null,"id":26,"money":100,"stuAge":"14","stuName":"王五","stuSex":"女"},{"classes":null
,"id":23,"money":300,"stuAge":"13","stuName":"李四","stuSex":"男"}]},"id":28,"money":100,"stuAge":"15","stuName"
:"张三","stuSex":"女"}]}
绑定的样式如下:$(function(){ $('#dg').datagrid({ url:'show_showStu.action', pagination:true, fitColumns:true, idField:'id', pageSize:10, pageList:[10,20,30] , columns:[[ {field:'id',title:'编号',width:100}, {field:'stuName',title:'姓名',width:100}, {field:'stuSex',title:'性别',width:100,align:'right'} , {field:'stuAge',title:'年龄',width:100,align:'right'} , {field:'money',title:'余额',width:100,align:'right'} , [{field:'?这里怎么取',title:'班级',width:100,align:'right'} ] ]] }); });
这个班级是一个数组怎么取值,求大神告知一二。
解决方案
直接配置为你classs,还需要配置formatter进行数组内容获取,最后的classes不要加[]这个,去掉
.........
{field:'money',title:'余额',width:100,align:'right'} ,
{field:'classes',title:'班级',width:100,align:'right',formatter:function(){
//v就是你的classes json对象
var r='',s=v.students;
r=v.name;
r+='学生人数:'+(s?'没有学生':s.length);
//其他的处理,如遍历students数组获取你要的人什么的东东
return r;
}}
解决方案二:
唉!我前几天没办法,把JSON串在后台改好了传过来
解决方案三:
这个问题问得好,不太好回答
解决方案四:
{field:'cname',title:'班级',width:100,align:'center',sortable:true,
editor:{type:'combobox',
options:{
valueField:'cname',
textField:'cname',
panelHeight:true,
url:'ShowClassServlet',
required:true
}}},]],
这里的cname,就是你查出的班级在后台转换成Json串传过来,就可以了
editor这个是将渲染成下拉框
班级就出来了
时间: 2025-01-30 06:20:24