Reputation: 1392
In my controller, I want to get a random record from the localstorage and display in the view, how can I do that?
In my config I have:
stores: ['Items']
In my function I have :
var mystore = (this.getStores())[0];
var index = this.getRandomInt(0, mystore.totalCount() -1);
var nextItem = mystore.getAt(index);
but it's stuck at the first line
Maybe there is an easier way?
Upvotes: 2
Views: 3761
Reputation: 12949
Here's the function you shoud use
var getRandomRecord = function(store){
var s = Ext.getStore('store');
var r = s.getAt(Math.floor(Math.random()*(s.getCount()-1)));
return r;
}
And you call it like this :
var randomRecord = getRandomRecord('Items');
Hope this helps
Upvotes: 0
Reputation: 6055
Since your store is called 'Items' i would:
var mystore = Ext.getStore('Items');
is the most reliable way to get the instance of the store.
Upvotes: 0