从dojo.store.jsonrest中删除项

从dojo.store.jsonrest中删除项,rest,dojo,store,Rest,Dojo,Store,我从这个教程开始 设置服务器端Restfull服务后,到目前为止一切都正常。我通过以下方式制作了树的上下文菜单: <ul dojoType="dijit.Menu" id="contextMenu" style="display: none;"> <li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconDelete" onclick="pages.remove(tn.item.id);"&g

我从这个教程开始

设置服务器端Restfull服务后,到目前为止一切都正常。我通过以下方式制作了树的上下文菜单:

<ul dojoType="dijit.Menu" id="contextMenu" style="display: none;">
<li dojoType="dijit.MenuItem" iconClass="dijitEditorIcon dijitEditorIconDelete" onclick="pages.remove(tn.item.id);">delete page</li>
</ul>

<script type="dojo/connect">
var menu = dijit.byId("contextMenu");
menu.bindDomNode(this.domNode);

dojo.connect(menu, "_openMyself", this, function(e){
    // get a hold of, and log out, the tree node that was the source of this open event
    tn = dijit.getEnclosingWidget(e.target);

    // contrived condition: disable all menu items except the "New Page" item
    dojo.forEach(menu.getChildren(), function(child){
        if(child.label != "Neue Seite")
        {
            child.set('disabled', typeof tn.item == 'undefined');
        }
    });
});
</script>

一切正常,但如果我现在对树中的项目做一些其他的事情,比如拖放一个项目到根目录,我以前删除过一个子目录。树不再正确地显示它。我认为store的remove方法只向服务器发送DELETE查询,而不从store中删除项目。如何获取存储区中要检查或删除的项的数组?

dijit.Tree是一个底层dojo.data模型的表示,您要对该树进行的任何更改实际上都需要对底层数据存储区进行。请参见此处的描述:因此,您不应该重写remove函数,而应该使用dojo.data API来修改存储,然后重新命名树以反映更改。查看各种可用方法的最佳来源是dojo nightly文件。具体来说,dojo.data文件如下:


你会考虑解释你的代码,这样任何阅读的人都知道为什么它会起作用吗?我不使用doJo.DATA模型。正如您在教程中所看到的,存储直接与树连接。不管怎样,我发现删除操作很有效。只有当旧的父项在删除后没有子项时,才会出现此问题。如果我现在添加一个新的子项或将另一个子项拖动到父项,则会出现一个加号,但没有函数性。有什么想法吗?由于某些原因,对new/addnl子项的引用未正确设置。加号表示树可以识别子对象,但底层指针有点不正确。。。我对树的理解是,它使用下面的dojo.data模型,而不管您的数据是在dojo.data模型中还是在dojo.store中。正如这里所讨论的,这可能很重要:存储区并不指定一组对象的实际数据结构。因此,这可能是一个商店与树对话的问题。我还想看看这里:特别是关于使用现有小部件和商店的部分。它讨论了大多数现有的WidJet如何与旧的dojo.data模型一起工作,并讨论了对象层次结构问题btwn父级和子级。。。
remove: function(objectId){

    this.onDelete({id: objectId});
    return dojo.store.JsonRest.prototype.remove.apply(this, arguments);

}
var item = tree.fetchItemByIdentity("selectedItem");  //find the item you want to remove
store.deleteItem(item);               //delete the item from the data store
store.save();                         //save the change made to the store