在我的控制器中,我想从本地存储中获取随机记录并显示在视图中,我该怎么做?
在我的配置中,我有:
stores: ['Items']
在我的功能中,我有:
var mystore = (this.getStores())[0];
var index = this.getRandomInt(0, mystore.totalCount() -1);
var nextItem = mystore.getAt(index);
但它卡在第一行
也许有更简单的方法?
在我的控制器中,我想从本地存储中获取随机记录并显示在视图中,我该怎么做?
在我的配置中,我有:
stores: ['Items']
在我的功能中,我有:
var mystore = (this.getStores())[0];
var index = this.getRandomInt(0, mystore.totalCount() -1);
var nextItem = mystore.getAt(index);
但它卡在第一行
也许有更简单的方法?
mystore.totalCount()
should be
mystore.getCount()
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
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.