ext store.load异步问题


store.load({callback : function(){

store.getCount();

}

});

//这样的话每次调用load的时候就会去调store.getCount()方法。立即就会得到值。

this.userStore.removeAll();

userStore.load({
callback : function(r, options, success) {
alert("callback");
if (success) {
for (var i = 0; i < r.length; i++) {
var record = r[i];
var v = record.data.userName;
alert(v);
}
}
}
});

Ext.Ajax.request({

url: '',

method: 'post',

async: false, //同步请求

success: function(response) {

}

});


使用ext的store.load(),之后然后使用store.getCount(),
store.load(parameter);
store.getCount();
发现其值始终为0,好像没有load成功,查了相关的资料发现,store.load其实是个异步方法,load之后的结果不能再load函数后马上显示。
如果需要改变这种方法,那么应该将store.getCount放在load的callback中。
例如:
https://blog.csdn.net/kunlong0909/article/details/7084311

猜你喜欢

转载自blog.csdn.net/weixin_42666837/article/details/86530622
ext