PDA

View Full Version : Can not get store.length



shadow_m
15 Nov 2011, 9:01 AM
Hi, I have problem with simple store:



ColumnSizeStore722 = Ext.create('Ext.data.JsonStore', {
autoLoad: false,
autoSync: true,
storeId: 'ColumnSizeStore722',
proxy: {
type: 'ajax',
url: './php/SelectColumnSize.php?GridName='+GridName,
reader: {
type: 'json',
root: 'data'
}
},
fields: [
{
name: 'size'
}
],
listeners: {
load: function() {
StoreLength = ColumnSizeStore722.data.length;
alert(StoreLength); //show 15
}
}
});
ColumnSizeStore722.load();
alert(StoreLength); //show "0". WHY???


Why I can not get ColumnSizeStore722.data.length after store load? How can I fix this? Thanks

zombeerose
15 Nov 2011, 9:52 AM
Why not use store.getCount (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.data.Store-method-getCount)()?

mankz
15 Nov 2011, 10:56 AM
store.getCount() would show the same. You're missing the fact that store.load is async, you have to do whatever post processing you need in the 'load' listener handler.

shadow_m
15 Nov 2011, 11:13 AM
Thank you for quick answer!
Actually it is only example, On real case I need to get record from ColumnSizeStore722.data.items[i].size
But my store is empty :-(