我創建了下面的網格組件:ExtJS的網格不會顯示任何數據
MyApp.grids.RelationshipMemberGrid = Ext.extend(Ext.grid.GridPanel, {
autoHeight: true,
iconCls: 'icon-grid',
title: 'Relationship Members',
frame: true,
viewConfig: { forceFit: true },
relationshipId: null,
documentId: null,
initComponent: function() {
if (this.verifyParameters()) {
// Initiate functionality
this.columns = this.buildColumns();
this.view = this.buildView();
this.store = this.buildStore();
this.store.load();
}
MyApp.grids.RelationshipMemberGrid.superclass.initComponent.call(this);
},
verifyParameters: function() {
// Verification code
},
buildColumns: function() {
return [{
header: 'Id',
dataIndex: 'Id',
sortable: true,
width: 10
}, {
header: 'Type',
dataIndex: 'ObjType',
sortable: true,
width: 10
}, {
header: 'Name',
dataIndex: 'Name',
sortable: true
}];
},
buildView: function() {
return new Ext.grid.GroupingView({
forceFit: true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Members" : "Member"]})'
});
},
buildStore: function() {
return new Ext.data.GroupingStore({
url: MyAppUrls.ListRelationshipMembers,
baseParams: { relationshipId: this.relationshipId },
root: 'data',
fields: ['Id', 'ObjType', 'Name'],
sortInfo: { field: 'Name', direction: 'ASC' },
groupField: 'ObjType'
});
}
});
網格正確渲染,並映射到MyAppUrls.ListRelationshipMembers
的URL是正確的。該數據被檢索,且ListRelationshipMembers
網址傳回下列JSON:
{"data":[{"Id":1,"ObjType":"topic","Name":"Test2"}]}
然而,即使網格渲染(列,邊框等)沒有數據顯示的實際電網雖然。由於這是我第一次使用數據存儲,所以我不確定自己做錯了什麼。任何幫助將是欣賞。
編輯:
我試圖更新商店必須通過下面的代碼讀者:
return new Ext.data.GroupingStore({
url: MyAppUrls.ListRelationshipMembers,
baseParams: { relationshipId: this.relationshipId },
fields: ['Id', 'ObjType', 'Name'],
sortInfo: { field: 'Name', direction: 'ASC' },
reader: new Ext.data.JsonReader({
root: 'data'
}),
groupField: 'ObjType'
});
沒有變化,數據網格沒有被填充記錄
工作。第二次嘗試發現我的問題是字段數組在我的GroupingStore中,當它應該在讀者中! – KallDrexx 2010-12-19 19:28:11