简体   繁体   English

Dojo-Dijit.Tree-更新树

[英]Dojo - Dijit.Tree - Updating Tree

I created a simple tree based on a TreeStoreModel which is backed by ItemFileWriteStore. 我创建了一个基于TreeStoreModel的简单树,该树由ItemFileWriteStore支持。 I tried updating my tree by deleting and adding items to the store as below, but could not. 我尝试通过删除存储并将其添加到商店中来更新树,如下所示,但是没有。

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! */   
});

I followed the lead from here , I must be missing something very trivial here. 我从这里开始 ,我一定在这里缺少一些琐碎的东西。 Please help. 请帮忙。

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

Taken from that page 取自该页面

How do I refresh a Tree from the store? 如何从商店刷新树?

This isn't supported. 不支持此功能。 The store needs to notify the tree of any changes to the data. 存储需要将对数据的任何更改通知树。 Currently this is really only supported (out of the box) by dojo.data.ItemFileWriteStore, as setting up a client-server dojo.data source where the server notifies the client whenever the data has changed is quite complicated, and beyond the scope of dojo, which is a client-only solution. 当前,这实际上仅由dojo.data.ItemFileWriteStore支持(开箱即用),因为设置客户端-服务器dojo.data源时,只要数据发生更改,服务器就会在通知客户端时通知客户端,这超出了范围dojo,这是一个仅用于客户端的解决方案。

The only way to update the tree is to re-draw it again :( 更新树的唯一方法是再次重画它:(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM