关于EasyUI Datagrid JSON对象内嵌对象的取值问题

如有这样一个JSON对象:

  1. {"users":[  
  2.         {"id":1,"role":{"id":1,name:"管理员"},"name":"NameA","TrueName":"name1"},  
  3.         {"id":1,"role":{"id":1,name:"经理"},"name":"NameB","TrueName":"name2"},  
  4.     ]  
  5. }  
在页面中,我要在EasyUI的datagrid中显示如下列:
id,role中的name, name则做如下处理:


  1. <table id="datagrid" class="easyui-datagrid" width="460px"  
  2. url="User!queryAllUser" title="用户表" auto-resize="true" pagination="true"  
  3. fitColumns="true">  
  4.     <thead>  
  5.         <tr>  
  6. <th field="id" checkbox="true"></th>  
  7. <th field="name">用户名</th>  
  8. <th field="role" formatter="formatRole">角色名</th>  
  9. <th field="TrueName">真实姓名</th>  
  10.         </tr>  
  11.     </thead>  
  12. </table>  
  13. <script>  
  14.     function formatRole(value){  
  15.         return value.name;  
  16.     };  
  17. </script>  

猜你喜欢

转载自blog.csdn.net/qq_40981281/article/details/79451441