store 中each()方法的使用应在load完使用,确切的说应该在on('load')事件中使用,
不懂就看一下下面的例子吧!。。。
不懂就看一下下面的例子吧!。。。
//获得store,这里假如store里有3条记录。
var i = 0;
var ds = grid.getStore();
\\
//以下是正确与不正确的例子
1)错误例子
ds.each(function(rec)
{ i++; }
);
result : i = 0;//表明each没有执行或此方法在数据加载前执行(后者的可能行更大)
2)正确例子
ds.on('load',function(store,records){
store.each(function(rec)
{ i++; }
);
});
result: i = 3;
下面看一下如何使grid中的checkBox为选中状态
var sm = grid.getSelectionModel();//get the seletion model
ds.on('load',function(store,records){
store.each(function(rec) {
//判断条件
if(....)
{ sm.selectRecords([rec]); }
);
});