javascript - Dojo - Dijit.Tree - 更新树

标签 javascript dojo javascript-framework

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

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 的引导,我一定在这里遗漏了一些非常微不足道的东西。请帮忙。

最佳答案

取自该页面

如何从商店刷新树?

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

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

关于javascript - Dojo - Dijit.Tree - 更新树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9081692/

相关文章:

javascript - 如何使用 forge-api for nodejs 获取包含更多错误消息详细信息的错误正文?

javascript - ASPxClientGridView.ApplyFilter 执行其工作后触发的客户端事件

javascript - dijit.tree 如何仅使用存储来实现折叠所有功能?

angularjs - 对于 SEO,我可以在我的 Angular 应用程序旁边提供一个静态 HTML 替代版本吗?

javascript - 从 Protractor 中的选项卡获取元素

javascript - 我如何更改视口(viewport)区域 extjs 4 的颜色?

eclipse - 显示标准/质量的 Dojo Web 应用程序示例?

javascript - 4 次查询后更新 Dojo 图表

jquery - 将原型(prototype)与 Jquery 一起使用

javascript - 提供与服务器端呈现的 html 的双向绑定(bind)的 JS 框架?