【问题标题】:Dojo - Dijit.Tree - Updating TreeDojo - Dijit.Tree - 更新树
【发布时间】:2012-02-23 07:10:37
【问题描述】:

我基于由 ItemFileWriteStore 支持的 TreeStoreModel 创建了一个简单的树。 我尝试通过删除项目并将项目添加到商店来更新我的树,如下所示,但不能。

dojo.require("dojo.data.ItemFileWriteStore");
dojo.require("dijit.Tree");
dojo.addOnLoad(function () {
    var tmpData = [{
            "name" : "Dell",
            "type" : "business",
            "businessid" : "1",
            "projectid" : "1",
            "submenu" : [{
                    "name" : "OTP",
                    "type" : "product",
                    "productid" : "100"
                }
            ]
        }
    ];

    var tmpData1 = [{
            "name" : "Lenovo",
            "type" : "business",
            "businessid" : "1",
            "projectid" : "1",
            "submenu" : [{
                    "name" : "OTP",
                    "type" : "product",
                    "productid" : "100"
                }
            ]
        }
    ];
    var store = new dojo.data.ItemFileWriteStore({
            data : {
                label : 'name',
                items : tmpData
            }
        });

    var treeModel = new dijit.tree.TreeStoreModel({
            store : store,
            query : {
                type : 'business'
            },
            childrenAttrs : ["submenu"]

        });

    var divTestTree = dojo.create("div", null, dojo.body(), "first");
    var mytree = new dijit.Tree({
            model : treeModel
        },
            divTestTree);
    /* Tree is created at this point */

    /* Delete the item from the store,  for some reason tempData is being reset*/
    store.deleteItem(tmpData[0]); 
    /* save */
    store.save();
    /* Tree shows up no more at this point */

    /* Try adding new item to the store */
    store.newItem(tmpData1[0]);
    /* save */
    store.save();
    /*nothing happens! */   
});

我跟随here 的领导,我一定错过了一些非常微不足道的东西。请帮忙。

【问题讨论】:

    标签: javascript dojo javascript-framework


    【解决方案1】:

    对于任何来这里寻找解决方案的人来说,“我怀疑有一个错误”是我在论坛上得到的唯一答案,所以这可能是一个错误 - goo.gl/M7xg7

    【讨论】:

      【解决方案2】:

      取自该页面

      如何刷新商店中的树?

      不支持。商店需要将数据的任何更改通知树。目前,这实际上只有 dojo.data.ItemFileWriteStore 支持(开箱即用),因为设置客户端-服务器 dojo.data 源,服务器在数据发生更改时通知客户端非常复杂,超出了dojo,这是一个仅限客户端的解决方案。

      更新树的唯一方法是重新绘制它:(

      【讨论】:

      • OP 正在使用 itemFileWriteStore
      • @7dr3am7 - 我正在使用 ItemFileWriteStore,那里的文档有点混乱......根据这里的文档dojotoolkit.org/reference-guide/dojo/data/… - 对商店的更改反映在树中,不确定 addItem。 ..
      • 对于任何来这里寻找解决方案的人来说,“我怀疑有一个错误”是我在论坛上得到的唯一答案,所以这可能是一个错误 - goo.gl/M7xg7跨度>
      猜你喜欢
      • 2015-12-02
      • 2012-06-05
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      相关资源
      最近更新 更多