延迟ExtJS中的网格重新加载

时间:2017-11-01 17:05:04

标签: javascript extjs delay

当我从商店中删除产品时,我的网格会在产品实际删除之前更新。这会导致我的产品在删除后仍显示在网格中。我怎样才能解决这个问题?

deleteProduct: function (a, b, c, d, e, responseObject) {
    var id = responseObject.data.ProductID;
    var gridStore = Ext.getCmp('prodDetailsGrid').getStore();

    Ext.Msg.confirm("Confirmation", "Do you want to permanently delete this product?", function (btnText) {
        if (btnText === "yes") {
            Direct.Product.DeleteProduct(id);
            Ext.toast('Product Deleted');
            var gridStore = Ext.getCmp('prodDetailsGrid').getStore();
            gridStore.load().delay(500);
        }
    })
}

3 个答案:

答案 0 :(得分:1)

您需要在请求完成后调用负载:

deleteProduct: function (a, b, c, d, e, responseObject) {
    var id = responseObject.data.ProductID;
    var gridStore = Ext.getCmp('prodDetailsGrid').getStore();

    Ext.Msg.confirm("Confirmation", "Do you want to permanently delete this product?", function (btnText) {
        if (btnText === "yes") {
            var gridStore = Ext.getCmp('prodDetailsGrid').getStore();
            Direct.Product.DeleteProduct(id, () => gridStore.load());
            Ext.toast('Product Deleted');
            gridStore.load();
        }
    })
}

答案 1 :(得分:0)

据我所知,您希望首先执行删除操作,并且只有在收到删除响应后才要重新加载商店。

这可以使用回调来实现。您可以将另一个参数作为函数传递给 Direct.Product.DeleteProduct ,并且可以在处理完成后执行传递的函数。

function modifyarrays!(length_of_arrays, price, lower_limit, steps_per_unit, succrate)
for pr_A in 1:101

    price[pr_A] = lower_limit + ((pr_A-1) / steps_per_unit)

  for d in 1:20
    if price[pr_A] == price1
        succrate[pr_A, d] = succrate1
    else
        succrate[pr_A, d] = succrate2
    end
  end
end

end

length_of_arrays = 101

lower_limit = 0
steps_per_unit = 1

price1 = 10

succrate1 = 5
succrate2 = 7

price = Array{Float64, 1}(101)
succrate = Array{Float64, 2}(101,20)


modifyarrays!(101, price, 0, 1, succrate)

println(succrate[11, 2])

否则您也可以使用承诺

    Dim dict1 = fileToDict(PriceList)
    Dim dict2 = dict1.ToDictionary(Function(y) Val(y))

如果您的DeleteProduct方法使用Ext.Ajax调用,您始终可以在Ext.Ajax.request的成功方法中调用回调。

答案 2 :(得分:0)

我能够解决自己的问题。他只是用代码改变的东西是在我的后端控制器调用之前添加gridStore var。我不确定为什么这会让它发挥作用......但我不会抱怨。

deleteProduct: function (a, b, c, d, e, responseObject) {
    var id = responseObject.data.ProductID;
    var gridStore = Ext.getCmp('prodDetailsGrid').getStore();

    Ext.Msg.confirm("Confirmation", "Do you want to permanently delete this product?", function (btnText) {
        if (btnText === "yes") {
            var gridStore = Ext.getCmp('prodDetailsGrid').getStore();
            Direct.Product.DeleteProduct(id);
            Ext.toast('Product Deleted');
            gridStore.load();
        }
    })
}