如何从树中删除项目

时间:2012-09-19 14:42:17

标签: extjs treeview crud

我尝试使用此示例并将基本CRUD添加到树中。

http://dev.sencha.com/deploy/ext-4.0.0/examples/tree/treegrid.html

现在,我只想从树中删除一个项目。我已添加按钮并点击此按钮:

click : function() {;
    var record = tree.getSelectionModel().getSelection()[0];
    store.destroy(record);
    store.sync();
}

我已经验证了记录和存储存在。商店的类型为TreeStore,如示例所示。如果我检查发送的请求,它只是[]。我目前在代理中的所有内容都是:

var store = Ext.create('Ext.data.TreeStore', {
    storeId : 'treeStore',
    model : 'Task',
    proxy : {
        type : 'ajax',
        // the store will get the content from the .json file
        url : '../resources/data/treegrid.json'
    },
    folderSort : true
});

单击“删除”不会删除当前选定的项目。我是否需要在代理中设置正确的销毁URL,为什么不在请求标头中发送有关需要删除的内容的任何详细信息?没有其他的例子可以从我能找到的树上做CRUD。

enter image description here


修改

请注意,使用store.destroy(record)时出现混淆的原因是Ext.data.Store方法remove(record)Ext.data.TreeStore没有。此外,销毁的简写方法是record.destroy()而不是record.remove(true)

但请注意,我收到了record.destroy()record.remove(true)的错误消息。据推测,商店需要保留要作为JSON发送的节点,因此请改用record.remove()

1 个答案:

答案 0 :(得分:13)

树存储没有方法销毁。 由于记录来自树店,因此它使用node interface进行装饰。所以使用remove方法(带有可选的destroy)。

    var record = tree.getSelectionModel().getSelection()[0];
    record.remove(true);
    store.sync();
相关问题