从dojo.store.jsonrest中删除项目 [英] delete item from a dojo.store.jsonrest

查看:124
本文介绍了从dojo.store.jsonrest中删除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从本教程开始 http://dojotoolkit.org/documentation/tutorials/1.6/ store_driven_tree /

设置我的ServerSide Restfull Service后,一切正常工作。我通过以下方式为树创建了一个上下文菜单:

after setting up my ServerSide Restfull Service everything is working so far. I made a contextmenu for the tree by:

<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>

现在我知道用户右键单击上下文菜单,并用页面删除它卸下摆臂(tn.item.id);从数据库。要通知树,我将覆盖删除功能:

Now I know on wich node the user made the right click for the contextmenu and delete it with "pages.remove(tn.item.id);" from the Database. To notify the tree I´m overriding the remove function:

remove: function(objectId){

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

}

一切都按预期工作,但如果我现在正在做一些其他事情与树中的项目像拖动n将一个项目删除到我之前删除一个孩子的根目录。树没有正确显示。我认为商店的删除方法只将DELETE查询发送到服务器,但不要从商店中删除该项。如何获取商店中的商品数组来检查或删除商品?

Everything works as expected but if im now doing some other things with the items in the tree like drag n drop an item to the root i was deleting a child before. The tree isn't showing it correctly anymore. I think the remove method of the store only sends the DELETE query to the Server but don't removes the item from the store. How can i get the array of the items in store to check and maybe to delete items?

推荐答案

dijit.Tree是介绍一个底层的dojo.data模型,并且您想要对树进行的任何更改都需要对基础数据存储进行。请参阅以下说明: http://dojotoolkit.org/reference-guide/ dijit / Tree.html#dijit-tree 因此,您不应该覆盖remove函数,而应该使用dojo.data API来修改存储,然后重新渲染树以反映更改。查看各种可用方法的最佳来源是dojo夜间文件。具体来说,dojo.data文件在这里: http://archive.dojotoolkit.org/ nightly / dojotoolkit / dojo / data /

The dijit.Tree is a presentation of an underlying dojo.data model, and any changes that you want to make to the tree really need to be done to the underlying data store. See the description here: http://dojotoolkit.org/reference-guide/dijit/Tree.html#dijit-tree So, instead of overriding the remove function, you should instead use the dojo.data API to modify the store, and then rerender the tree to reflect the changes. The best source for looking at the various methods available is in the dojo nightly files. Specifically, the dojo.data files are here: http://archive.dojotoolkit.org/nightly/dojotoolkit/dojo/data/

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

这篇关于从dojo.store.jsonrest中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆