最近做EXTJS4 的 东西 遇到了问题 想求教 大家:
对嵌入对象做了mapping 可是 取不到 请朋友们指点:
后台发送过来的json 数据 {"totalRecord":26,"employees":{ "id":1, "dept":{"name":"咨询部",id":3,"description":null,"code":null} ,"user":null, "title":{"name":"咨询","id":3} } } store: this.store = Ext.create('Ext.data.Store', { fields: ['id',{name:'deptName',mapping:'dept.name'}, {name:'titleName',mapping:'title.name'}, ], pageSize:20, proxy: { type: 'ajax', actionMethods : 'post', url : "aa/aaa", timeout : 1000*60*3, reader: { totalProperty:'totalRecord', type: 'json', root: 'employees', remoteSort: true } } }); grid 中的对应列 this.columns =[ {xtype: 'rownumberer',width: 50, sortable: false,align:'center'}, {header: '部门', dataIndex: 'deptName',width:150}, {header: '职位', dataIndex: 'titleName',width:150} ], fireBug 报出的错误obj.dept is null 请问 这个 store 的 fields 应该怎么写?
请问 这个 store 的 fields 应该怎么写?
[code="java"]
<br> Ext.onReady(function(){<br> //创建表格数据<br> var datas = {"totalRecord":26,"employees":{<br><br> "id":1,<br><br> "dept":{"name":"咨询部","id":3,"description":null,"code":null}, //你的数据id前面少了“<br> "user":null,<br><br> "title":{"name":"咨询","id":3}<br><br> }<br><br> };</p> <pre><code> //创建Grid表格组件 Ext.create('Ext.grid.Panel',{ title : '简单Grid表格示例', renderTo: Ext.getBody(), width:200, height:130, frame:true, viewConfig: { forceFit : true, stripeRows: true//在表格中显示斑马线 }, store: {//配置数据源 fields: [ {name:'id',mapping:'id'}, {name:'deptName',mapping:'dept.name'}, {name:'titleName',mapping:'title.name'} ], proxy: { type: 'memory',//Ext.data.proxy.Memory内存代理 data : datas,//读取内嵌数据 reader: { totalProperty:'totalRecord', type: 'json', root: 'employees' } }, autoLoad: true//自动加载 }, columns: [//配置表格列 {header: "id", width: 30, dataIndex: 'id', sortable: true}, {header: "部门", width: 80, dataIndex: 'deptName', sortable: true}, {header: "职位", width: 80, dataIndex: 'titleName', sortable: true} ] }); }); </code></pre> <p>
[/code]
上面为本地测试代码 数据显示成功了 呵呵