Extjs學習筆記——Ext.data.JsonStore使用說明,ext.data.jsonstore
Ext.data.JsonStore繼承於Ext.data.Store,使得從遠程JSON資料建立stores更為方便的簡單輔助類。JsonStore合成了Ext.data.HttpProxy與Ext.data.JsonReader兩者。如果你需要其他類型的proxy或reader組合,那麼你要建立以Ext.data.Store為基類的配置。
代碼執行個體:
var store = new Ext.data.JsonStore({ id:'id', url: 'get-images.php', root: 'images', totalProperty: 'rowCount', fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]});
他的傳回值將形成如下的對象:
{ images: [ {name: 'Image one', url:'/GetImage.php?id=1', size:46.5, lastmod: new Date(2007, 10, 29)}, {name: 'Image Two', url:'/GetImage.php?id=2', size:43.2, lastmod: new Date(2007, 10, 30)} ]}
下面我們依次說明下幾個參數的含義:
id(String):用來唯一標識
url(String):如果有值傳入,會為該URL建立一個HttpProxy對象
root(String):JSON對象的key指定,這裡指的是伺服器傳遞過來的json變數的命名
totalProperty:這裡指的是查詢出來的條數,也是由伺服器傳遞過來
fields(Object[]):對象數組集合
在實際應用中fields我們可以使用遍曆list等方式往裡面傳值。