如何从树中删除项目

Ara*_*yan 8 treeview extjs 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();
}
Run Code Online (Sandbox Code Playgroud)

我已经验证了记录和存储存在.商店的类型为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
});
Run Code Online (Sandbox Code Playgroud)

单击"删除"不会删除当前选定的项目.我是否需要在代理中设置正确的销毁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().

nsc*_*rob 13

树商店没有方法销毁.由于记录来自树库,因此它使用节点接口进行装饰.所以使用remove方法(带有可选的destroy).

    var record = tree.getSelectionModel().getSelection()[0];
    record.remove(true);
    store.sync();
Run Code Online (Sandbox Code Playgroud)

  • 我使用`record.remove()`否则会出错. (3认同)