2013-01-14 19 views
0

在Sencha Architect上使用ExtJs4.1。使用CheckboxSelectionModel從網格刪除多個項目

我在onDeleteButton代碼下面的代碼

onDeleteButtonClick: function(button, e, options) { 
    var active = this.activeRecord; 
    var myGrid = Ext.getCmp('publisherResultsGridView'), 
     sm = myGrid.getSelectionModel(), 
     selection = sm.getSelection(); // gives you a array of records(models) 

    if (selection.length > 0){ 
      for(var i = 0; i < selection.length; i++) { 
          this.application.log('OnDeleteItemID is ' + selection); 
      } 
      this.remove(selection); 
    } 

代碼Remove功能

remove: function(record) { 
     var store = Ext.getStore('PublisherProperties'); 
     store.proxy.url = MasterDataManager.globals.url + "Publishers/"; 
     store.remove(record); 
     store.sync(); 

當我運行它,我可以看到對象的數組在我的日誌,我也沒得到執行remove函數後的任何錯誤。但商店不更新,我的意思是它不刪除選定的項目。

有人可以幫我。

感謝

+1

你能後是如何被創建存儲。這聽起來像設置代理API有問題。 http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Server-cfg-api。或者,getStore中的商店可能是錯誤的。每個記錄都有一個存儲屬性,這將是不使用硬編碼ID獲取引用的首選方式。 – pllee

回答

1

我通過以下的改變來解決我的問題。

onDeleteButtonClick

if (selection.length > 0){ 
       for(var i = 0; i < selection.length; i++) { 
           this.application.log('OnDeleteItemID is ' + selection[i].data.id); 
           this.remove(selection[i]); 
       } 

     } 

Remove功能

remove: function(record) { 
    var store = Ext.getStore('PublisherProperties'); 
    this.application.log('Remove Function is ' + record); 
    store.proxy.url = MasterDataManager.globals.url + "Publishers/" + record.data.id; 
    store.load({ 
         scope : this, 
         callback : function(records, operation, success){ 
          if (records.length > 0){ 
           var store2 = Ext.getStore('PublisherProperties'); 
             store2.proxy.url = MasterDataManager.globals.url + "Publishers/"; 
             store2.remove(records[0]); 
             store2.sync(); 
          } 
         } 
      }); 
    //store.remove(record); 
    //store.sync();