【问题标题】:How to delete items from a Tree如何从树中删除项目
【发布时间】:2015-08-24 03:19:05
【问题描述】:

我尝试使用此示例并将基本 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 的示例。


编辑:

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

但是请注意,我在执行 record.destroy()record.remove(true) 时收到了错误。大概商店需要保留节点以作为 JSON 发送,因此请改用record.remove()

【问题讨论】:

    标签: extjs treeview crud


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,我犯了一个愚蠢的错误 :) 在发送到代理之前,我还可以看到带有 store.getRemovedRecords() 的已删除项目。
    猜你喜欢
    • 2020-09-06
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2013-05-01
    • 2017-02-14
    • 2019-05-01
    • 2019-05-29
    相关资源
    最近更新 更多