-
15 Mar 2012 12:43 PM #1
Access the store
Access the store
Hello,
i'm a little bit confused...this is the code:
this print 0. But there is a record, in fact if i use this store into a grid one row is displayed with correct data.Code:Ext.onReady(function () { Ext.define('Info', { extend: 'Ext.data.Model', fields: [ { name: 'first', type: 'string' }, { name: 'last', type: 'string' }, { name: 'codu', type: 'number' } ] }); // create the Data Store var store = Ext.create('Ext.data.Store', { model: 'Info', proxy: { type: 'ajax', url : 'info.php', reader: { type: 'json', root: 'info', successProperty: 'success' } }, autoLoad: true }); var fst = store.getCount(); document.write(fst); });
So, why it return 0?
I wanna use the store var for access the data; example:
var myVar = store.first();
var myVar2 = myVar.get('first');
but it doesn't work.
Thanks for help
-
16 Mar 2012 12:28 AM #2
You can use this
Where index is the index of the store record you want to accessCode:record = store.getAt(index);id = record.get('id');
-
16 Mar 2012 1:42 AM #3
mmm...i don't think will work.
i repeat that getCount retrieve a 0 value.
i've tried:
record = store.getAt(0);
but it return undefined. So what should i put into the index value?
thanks for reply
-
16 Mar 2012 2:18 AM #4
Loading the store is an asynchronous event and your code won't wait until it has completed, so your store.getCount() will be executing before the store had loaded.
To see it in action, add a listener to your store:
If you put a console.log statement after your document.write you should see the order in which things happen.Code:listeners : { load : function(store) { console.log("store count:" + store.getCount()); } }
Hope this helps.
-
16 Mar 2012 6:51 AM #5
sorry but i'm newbie with this framework...i don't understand exactly where i have to put my listener. can u post a complete code based on my first post code?
thanks a lot
-
16 Mar 2012 6:54 AM #6
ok, forget it..solved and thank you very much



Reply With Quote