extjs - 如何从树中删除项目

标签 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,为什么它不发送有关需要在请求 header 中删除的内容的任何详细信息?没有其他从我能找到的树中执行 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()反而。

最佳答案

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

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

关于extjs - 如何从树中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12497094/

相关文章:

model-view-controller - 正确的 extjs MVC 文件夹结构

c# - .NET/C# 中的 TreeView 双击行为

c# - NodeMouseClick 问题

sql-server - Windows 10 通用应用程序从 SQL Server 获取数据

javascript - ExtJS X模板

ExtJs - 使文本区域始终适合父面板

ExtJS 4 跟踪组件的所有事件

angular - Angular 4 中的树结构

Yii2 CRUD : How to implement Cancel button

AngularJS,用于 CRUD UI 的 DRY Controller