2009-07-31 77 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設置了一個斷點並逐步完成了這個過程嗎?