我似乎无法让PagingToolbar
在我的网格上正常工作。无论如何,它告诉我返回0结果,即使我收回了所有数据。
Ext.onReady(function() {
var data = '{"elements":[{"element":{"name":"value 1","id":"element 1","attributes":[{"attrname":"id","attrvalue":"This is the ID"},{"attrname":"name","attrvalue":"This is the name"},{"attrname":"description","attrvalue":"This is the description"},{"attrname":"table_name","attrvalue":"This is the table"}]}},{"element":{"name":"value 2","id":"element 2","attributes":[{"attrname":"id","attrvalue":"This is the ID 2"},{"attrname":"name","attrvalue":"This is the name 2"},{"attrname":"description","attrvalue":"This is the description 2"},{"attrname":"table_name","attrvalue":"This is the table 2"}]}}]}';
var store = Ext.create('Ext.data.Store', {
fields: ['id', 'name', 'description', 'table_name'],
proxy: {
type: 'memory'
}
})
Ext.create('Ext.grid.Panel', {
title: 'Test Data',
store: store,
pageSize: 2
columns: [{
text: 'ID',
dataIndex: 'id'
}, {
text: 'Name',
dataIndex: 'name'
}, {
text: 'Description',
dataIndex: 'description'
}, {
text: 'Table Name',
dataIndex: 'table_name'
}],
dockedItems: [{
xtype: 'pagingtoolbar',
store: store,
pageSize: 2,
dock: 'bottom',
displayInfo: true
}]
renderTo: Ext.getBody()
});
var decoded = Ext.decode( data );
// loop over decoded data
for( var i=0; i<decoded.elements.length; i++ ) {
var element = decoded.elements[ i ].element;
// set implicit model
var model = {};
// loop over attributes
for( var x=0; x<element.attributes.length; x++ ) {
var attribute = element.attributes[ x ];
model[ attribute.attrname ] = attribute.attrvalue;
}
// implicitly cast data as Model
store.add( model );
}
})
帮助?