2009-07-31 55 views
2

我必须删除编辑器网格中的选定项目。首先加载商店,用户可以选择添加或删除空白行到这个网格,然后他们可以编辑。问题不在于删除从商店加载的初始记录。当我添加一个额外的行,编辑它然后选择删除它(用户可能认为他不需要这一行)时,问题就出现了。Extjs - 从商店中删除新添加的选定项目

看来,当我想使用store.getModifiedRecords保存更改时,它仍然会看到已删除的行,并对其进行处理。这里是删除按钮:

442    
443     text:'Remove', 
444     tooltip:'Remove attribute', 
445     iconCls:'silk-table_delete', 
446     handler: function() { 
447      var selectedItem = attributeEditor.getSelectionModel().getSelected(); 
448 
449      // Check if we have selected item 
450      if (selectedItem) { 
451       // Get selected item value 
452       var attribute = selectedItem.get('Name'); 
453 
454       // Remove selected 
455       attributeStore.remove(selectedItem); 
456 
457       // Add to our removed attributes hash 
458       if (id) { 
459        RemovedAttributes.push(attribute); 
460       } 
461      } else { 
462       wispUserFormWindow.getEl().mask(); 
463 
464       // Display error 
465       Ext.Msg.show({ 
466        title: "Nothing selected", 
467        msg: "No attribute selected", 
468        icon: Ext.MessageBox.ERROR, 
469        buttons: Ext.Msg.CANCEL, 
470        modal: false, 
471        fn: function() { 
472         wispUserFormWindow.getEl().unmask(); 
473        } 
474       }); 
475      } 
476     } 
477    } 
+0

只是一个更新..仍然不知道这是为什么发生,但我所做的w ^与之前一样,请检查删除列表中是否有任何项目匹配,并将它们从请求列表中删除。 – imnotneo 2009-08-03 07:27:50

回答

2

这就是store.getModifiedRecords()的工作原理。修改后的记录记录存储在一个名为修改的商店对象中的数组中。从商店中删除商品时,默认情况下不会删除商品。

下面是从商店

remove : function(record){ 
    var index = this.data.indexOf(record); 
    this.data.removeAt(index); 
    if(this.pruneModifiedRecords){ 
     this.modified.remove(record); 
    } 
    if(this.snapshot){ 
     this.snapshot.remove(record); 
    } 
    this.fireEvent("remove", this, record, index); 
} 

实际删除()。这意味着该项目是从修改列表只有在指定的pruneModifiedRecords期权价值为真去除。默认情况下,此值为false,如Store API中所述。

如果您希望从修改的列表中移除新添加的项目,你必须设置pruneModifiedRecords作为真正的价值创造店 防爆时:

var stote = new Ext.data.SimpleStore({ 
    fields: [], 
    data: [], 
    pruneModifiedRecords: true 
}) 
0

关闭我的头顶,我看不出为什么你的代码会以这种方式工作,因为它看起来是正确的。你用Firebug设置了一个断点并逐步完成了这个过程吗?