2015-09-15 83 views
0

我有這樣的JSON:ExtJS的6網+ JSON

{ 
    "aaa": { 
     "list": { 
      "count":"1", 
      "data": [ 
       {"id":"1","username":"user1","email":"[email protected]"} 
      ] 
     } 
    } 
} 

這是我的商店:

var store = Ext.create('Ext.data.Store', { 
    fields : [ 'id', 
       'username', 
       'email'], 
    autoLoad : true, 
    proxy: { 
     type: 'ajax', 
     api: { 
      read: 'server/users' 
     }, 
     reader: { 
      type: 'json', 
      successProperty: 'success', 
      root: 'data', 
      messageProperty: 'message' 
     } 
    } 
}); 

這是我的網格:

xtype: 'grid', 
title: 'Users', 
id: 'users', 
store: store, 
columns: { 
    items: [ 
    {text: 'ID', dataIndex: 'id', editor: 'textfield'}, 
    {text: 'Name', dataIndex: 'name', editor: 'textfield' }, 
    {text: 'Email', dataIndex: 'email', editor: 'textfield' }, 
] 
}, 

但是這個代碼是不工作。我沒有在我的網格上顯示JSON數據。我認爲問題是我沒有達到JSON元素。
我該如何達到這個要素? (aaa.data.id,aaa.data.name,aaa.data.email不起作用)

+0

如果路徑始終是靜態的,您可以在''''''config''中指定'root':'aaa.list.data' – weeksdev

回答

1

既然你不想(或不能)改變你的JSON的結構,你的JSON數據結構更改代理的讀者在你的店裏記者。

reader: { 
    type: 'json', 
    rootProperty: 'aaa.list.data', 
    totalProperty: 'aaa.list.count' 
} 
0

root應該是root: 'aaa.list.data'root應該指向記錄數組。 data沒有出現在完全返回的頂級對象中。這就好比說:

var o = { 
    aaa: { 
     data: [{}] 
    } 
} 
console.log(o.data); // Nothing