2
我想通過使用JsonStore在網格中顯示數據。 網格呈現,但它不顯示數據。ExtJS Grid不加載數據
通過API.ashx返回的JSON數據:
[{"Account":{"Username":"root","Password":null,"Enabled":true,"Id":1},"Text":"Hallo Welt!","Id":1},{"Account":{"Username":"root","Password":null,"Enabled":true,"Id":1},"Text":"hihihi","Id":3}]
我的代碼:
Ext.onReady(function() {
var store = new Ext.data.JsonStore({
url: 'API.ashx?type=notes&action=getAll',
root: 'Note',
autoload: true,
fields: ['Text', { name: 'Id', type: 'int'}]
});
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{
id: 'Note',
header: 'Id',
width: 25,
sortable: true,
dataIndex: 'Id'
},
{
header: 'Text',
width: 160,
sortable: true,
dataIndex: 'Text'
}
],
stripeRows: true,
autoExpandColumn: 'Note',
height: 350,
width: 600,
title: 'Notes',
stateful: true,
stateId: 'grid'
});
store.load();
grid.render('grid-example');
});
當您配置「root」時,您指向應該讀取記錄的JSON的節點。在你給出的例子中,它看起來像一組帳戶,所以你不需要指定一個帳戶。 – 2012-05-31 20:45:56