jquery easyui datagrid 嵌套对象绑定

jquery easyui datagrid 嵌套对象绑定,网上很多资料说是easyui本身不支持嵌套对象绑定,但很多时候我们恰恰需要这种嵌套对象绑定,而实际上是可以实现且支持的,只需调用formatter函数就可以实现。

json 格式:

{                                                      
 "total":239,                                                      
 "rows":[                                                          
  {"code":"001","user":{"id":1,"name":"name1"},"addr":"Address 11","col4":"col4 data"},         
  {"code":"002","user":{"id":1,"name":"name1"},"addr":"Address 13","col4":"col4 data"},         
  {"code":"003","user":{"id":1,"name":"name1"},"addr":"Address 87","col4":"col4 data"},         
  {"code":"004","user":{"id":1,"name":"name1"},"addr":"Address 63","col4":"col4 data"},         
  {"code":"005","user":{"id":1,"name":"name1"},"addr":"Address 45","col4":"col4 data"},         
  {"code":"006","user":{"id":1,"name":"name1"},"addr":"Address 16","col4":"col4 data"},          
  {"code":"007","user":{"id":1,"name":"name1"},"addr":"Address 27","col4":"col4 data"},          
  {"code":"008","user":{"id":1,"name":"name1"},"addr":"Address 81","col4":"col4 data"},          
  {"code":"009","user":{"id":1,"name":"name1"},"addr":"Address 69","col4":"col4 data"},          
  {"code":"010","user":{"id":1,"name":"name1"},"addr":"Address 78","col4":"col4 data"}     
 ]                                                          
}

                                                         
js代码:

{field:'Id',title:'Id',width:120,
      formatter:function(value,rec){
       return rec.user.id;
      }
     },
     {field:'Name',title:'Name',width:120,
      formatter:function(value,rec){
       return rec.user.name;
      }
     }

注意,field命名是不能重复的,这样就可以实现嵌套对象绑定了

相关推荐