未在loadData上加载分页的Extjs网格
我试图使用loaddata在带有分页工具栏的extjs网格中加载数据,但它显示的是空网格。 返回的数据是未在loadData上加载分页的Extjs网格,extjs,extjs4,Extjs,Extjs4,我试图使用loaddata在带有分页工具栏的extjs网格中加载数据,但它显示的是空网格。 返回的数据是 { "data": [{ "id": "user1", "title": "index0" }, { "id": "user2", "title": "index1" }, { "id": "user3",
{
"data": [{
"id": "user1",
"title": "index0"
}, {
"id": "user2",
"title": "index1"
}, {
"id": "user3",
"title": "index2"
}, {
"id": "user4",
"title": "index3"
}],
"total": 8,
}
我的代码看起来像
initcomponent:function(){
defaultModel:[{
header: 'Date',
dataIndex: 'id',
sortable: true
},
{
header: 'title',
dataIndex: 'title',
sortable: false,
}];
}
this.currStore = Ext.create('Ext.data.Store', {
fields : ['id','title'],
pageSize:4,
autoLoad:false,
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'data',
totalProperty:'total',
}
}
});
this.currStore.load({
params:{
start:0,
limit: 4,
}
});
var config =
{
columns : this.defaultModel,
store : this.currStore,
columnLines : true,
loadMask : true,
autoScroll : true,
tbar : [{
xtype : 'button',
text : 'Refresh',
iconCls : 'btn-refresh',
scope : this,
handler : this.refreshGridData
}],
dockedItems: [{
xtype: 'pagingtoolbar',
store: this.currStore, // same store GridPanel is using
dock: 'bottom',
id:'pagingErrNot1',
pageSize:4,
displayInfo: true,
emptyMsg: "No notification to display",
listeners:{
beforechange : {
scope : this,
fn : function(pagingtoolbar,pageNumber,scope)
{
}
}
}
}],
};
Ext.apply(this,config);
this.callParent(arguments);
}
数据采用上面给出的格式,从服务器端返回数据后调用setdata
setData:function(data)
{
this.getStore().loadData(data);
this.getView().refresh();
}
但加载数据后,网格为空,pagingtoolbar显示已禁用。我做错了什么?它可能会引发错误。请打开chrome控制台查看,并将错误附加到您的帖子中。编辑:试试这个:
this.getStore().loadData(data.data)代码>它不会抛出任何错误。如果我加载'data.data',那么我们如何设置'totalProperty'。这就是为什么你必须使用远程代理,而不是内存。您不能以这种方式将分页与内存代理一起使用。为什么不使用ajax或jsonp代理,以便store可以在内部处理所有事情?如果您的数据是静态的或正在测试的,您应该在store中插入数据代码。您还可以使用this.getStore().setData(data)