PDA

View Full Version : Get records from store in view.View



AndreyPris
23 Jan 2015, 2:07 AM
Get records from store in view.View

Who can explain me why code work in that way:



Ext.define('MyApp.view.myView',{
extend: 'Ext.view.View',
alias: 'widget.evtView',
store: 'MyApp.store.myStore',
tpl: new Ext.XTemplate('<div class="evt"',
'style="background-color: green; position: absolute; width: 150px; height: 150px; top: 300px; left: 300px; z-index: 3">',
'Hello World',
'</div>'),
itemSelector: 'div.evt',
testMethod: function(){
console.log('Inside test method!');
},
initComponent: function () {
var me = this;
me.callParent();
me.getStore().load();
console.log(me.getStore().getCount()); // '0'
me.on('beforeshow', function() {
console.log(me.getStore().getCount()); // '99'
});
}
});

Why function getCount for store first returns 0 then return 99?

Jad
23 Jan 2015, 6:07 AM
me.getStore().load();console.log(me.getStore().getCount()); // '0' it's not loaded yet
me.on('beforeshow', function() { console.log(me.getStore().getCount()); // '99' it's probably loaded becose you have lunch the load in the init });

AndreyPris
23 Jan 2015, 6:34 AM
1) use pls code tags; 2) I use autoLoad for store and result the same;

skirtle
24 Jan 2015, 8:17 AM
Store loading is asynchronous. I assume there's a delay between the view being constructed and shown, such that beforeshow fires after the store has had chance to load.

AndreyPris
26 Jan 2015, 4:43 AM
You are sure or this is your opinion? Because my store load data from JSON which located on my PC. Is any event like "after store load"? Or how can I create this event?

Jad
26 Jan 2015, 5:19 AM
me.getStore().load(function () {
// executed on this load
});



or



me.getStore().on('load', funtion() {
// executed on each load
});

AndreyPris
27 Jan 2015, 7:57 AM
Thx Jad you are right. Its work for me.