我发现了一种奇怪的removeAll行为。我正在使用ExtJS 4.2,我不知道在其他较新的版本中是否会发生同样的情况。我在网格的tbar中有这样的代码:
{
itemId: 'delete',
text: 'Delete',
iconCls: 'icon-delete',
disabled: true,
handler: function() {
var selection = this.up('grid').getView().getSelectionModel().getSelection()[0];
if (selection) {
var numItems = storeProdutos.data.items.length;
var store = this.up('grid').getStore();
if(numItems != 0) {
// point 2
Ext.Msg.confirm('Confirm', 'Do you want to delete?', function(button){
if(button === 'yes') {
gridProduto.getStore().removeAll();
store.remove(selection);
gridProduto.getStore().clearFilter();
gridProduto.getStore().load();
gridMercado.getSelectionModel().select(0);
}
});
} else {
store.remove(selection);
gridProduto.getStore().clearFilter();
gridProduto.getStore().load();
gridMercado.getSelectionModel().select(0);
}
}
}
}当我试图删除它时,它会出现在消息框中,我会说是。
然后删除store.remove(选择),但不删除gridProduto.getStore.removeAll()。奇怪的是,在php删除脚本中,一切都成功了。
最奇怪的是,如果我将gridProduto.getStore.removeAll()放在代码的点2上,并再次执行所有操作,那么它就成功了!
我相信这和留言箱有关。
有人知道我怎么解决这个问题吗?
PS:我的商店有一个使用ajax删除的代理。就像这样:
storeProdutos = Ext.create('Ext.data.Store',{
...
proxy: {
type: 'ajax',
api: {
destroy: '/path/someScript.php'
}
}
}发布于 2016-05-13 22:31:55
我想您已经将autoSync设置为true,因为您没有在任何地方调用sync()。
问题是sync (由removeAll触发)和load操作的时间问题。如果将removeAll放入第2点,则在单击消息框(然后触发load)之前,将执行并完成removeAll。但是在这里,您需要启动两个Ajax调用:removeAll调用和load调用--这两个调用同时进行。由于存储在默认情况下异步启动调用,因此只执行最后一个调用。
您可以通过同步创建存储库(我认为这是一个黑客)来解决这一问题,或者更好的方法是从存储中删除autoSync,然后只从remove回调加载,如下所示:
gridProduto.getStore().removeAll();
gridProduto.getStore().sync({
callback:function() {
store.remove(selection);
gridProduto.getStore().clearFilter();
gridProduto.getStore().load();
gridMercado.getSelectionModel().select(0);
}
});https://stackoverflow.com/questions/37217564
复制相似问题