ExtJS removeAll不起作用

时间:2016-05-13 19:05:21

标签: extjs extjs4 messagebox removeall

我检测到了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'
            }
}
}

1 个答案:

答案 0 :(得分:1)

我猜你将autoSync设置为true,因为你没有在任何地方调用sync()。

问题是sync(由removeAll触发)和load操作的时间。如果您将removeAll放入第2点,removeAll将被执行并完成,然后您可以点击消息框(然后触发load)。但是在这种情况下,您可以同时启动两个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);
    }
});