我有两个商店,其中 autoload: true
正在加载数据。我想在两者加载后填充我的用户界面。我遵循 MVC 架构,所以在我的 Controller 中,我尝试做这样的事情:
store1.on('load', me.setUpIfBothStoresReady, me);
store2.on('load', me.setUpIfBothStoresReady, me);
setUpIfBothStoresReady: function() {
if(store1.isSuccessfullyLoaded() && store2.isSuccessfullyLoaded()) {
// do work
}
}
问题是,此时,一个或两个存储都可能已经加载。除了手动控制这些商店的负载之外,是否有一些设计模式我可以在两者都完成后才可以使用?
最佳答案
您可以将whenjs之类的东西与延迟事件一起使用。
https://github.com/cujojs/when/wiki/Examples
或者编写您自己的:
loadStores: function() {
...
me.loaded = 0;
store1.on('load', me.setUpIfBothStoresReady, me);
store2.on('load', me.setUpIfBothStoresReady, me);
},
...
setUpIfBothStoresReady: function() {
++this.loaded;
if (this.loaded == 2) {
//do work
}
}
如果你有几个商店,最好使用数组。
关于javascript - ExtJS如何在两个异步事件后设置一个 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16095696/