ExtJS 6.2从商店更新TreeGrid数据,无需从服务器重新加载

时间:2016-10-24 18:55:03

标签: javascript extjs extjs6 extjs6-classic

我有两个共享同一商店的树网格。当我将一个项目从一个拖到另一个时,所有正确的更新似乎都会发生(记录从左侧树上的位置消失,右侧树上的位置,左侧树现在也显示新的位置)。

但是,如果我尝试将同一条记录拖回其原始位置,则看起来它的父级从未更新过以表示它已离开。

我正在检查是否可以放置一个项目:

listeners: {
            nodedragover: function(targetNode, position, dragData, e, eOpts) {
        console.log("Trying to drop");
        var ruleStore = this.getStore('rules');

        // Ensure leaf is adding as a leaf
        if (position === 'before') {
            return false;
        }

        // Check first that the target is a pool and not a leaf
        if (targetNode.data.leaf) {
            console.log("A leaf! Can't drop here")
            return false;
        } else {
            console.log("A node! Drop it like it's hot");
        }

        var allowDrop = true;
        var dropMessage = [];

        var records = dragData.records;
        var targetPool = targetNode.data;
        console.log("Dragdata: ", dragData);
        console.log("targetPool: ", targetPool);
        console.log("Store: ", Ext.getStore('Pools'));

        // Check platform, sample names, indicies
        for (var i = 0; i < records.length; i++) {
            var rec = records[i].data;
            if (rec.platform !== targetPool.platform) {
                allowDrop = false;
                dropMessage.push("Sample platform does not match target pool platform");
                break;
            } else if (targetPool.children.map(
                function(child){ return child.sample_name;}).indexOf(rec.sample_name) > -1) {
                allowDrop = false;
                dropMessage.push("Sample is already in this pool");
                break;
            } else if (targetPool.children.map(
                function(child){ return child.sample_index;}).indexOf(rec.sample_index) > -1) {
                allowDrop = false;
                dropMessage.push("Sample index is already in this pool");
                break;
            }
        }
        console.log(dropMessage);
        return allowDrop;
    },

当我使用Ext.getStore(&#39; Pools&#39;)获得商店时,它反映该项目已从其旧的父项中删除,现在位于新的父项上。但是,来自nodedragover事件的targetNode仍然具有旧状态。

如何让树形视图反映商店,但不会从服务器重新加载商店(这应该都是客户端完成的)?

我觉得我在这里缺少一些基本概念。

1 个答案:

答案 0 :(得分:1)

您可以使用

treeView.refresh();

treeView.refreshNode(recordModified);

因为树视图是从view.table扩展的 这里是文档http://docs.sencha.com/extjs/6.0.2/classic/Ext.view.Table.html#method-refresh

相关问题