2015-06-14 34 views
1

我使用gpl版本的extjs5.1.1而沒有sencha cmd。
在我的應用程序中,網格顯示正確的商店。
在窗口中,有一個複選框至極代碼是:ExtJS5存儲過濾器「未捕獲TypeError:無法讀取未定義的屬性」獲得「

{ 
    xtype : 'checkbox', 
    itemId : 'employeeFilter', 
    value : false, 
    boxLabel : 'Show inaktiv users', 
    margin : '0 5 0 5', 
    listeners: { 
     change: function(checkbox, newValue, oldValue, eOpts) { 
      var store = this.up('window').getComponent('employeeGrid').getStore(); 
      if (newValue) { 
       console.log('clearFilter'); 
       store.clearFilter(); 
      } else { 
       console.log('rightFilter'); 
       store.rightFilter(); 
      } 
     } 
    } 
}] 

可變store指向正確網格存儲。我可以在控制檯中看到消息「clearFilter」和「rightFilter」。

商店代碼:

Ext.define('Chronos.store.manage.Employees', { 
    extend : 'Ext.data.Store', 

    model  : 'Chronos.model.manage.Employee', 
    autoLoad : false, 
    autoSync : true, 
    sortOnLoad : false, 
    pageSize : 0, 

    rightFilter: function() { 
     this.filterBy(function(record) { 
      return record.get('rights') >= 0; 
     }); 
    }, 

    proxy : { 
     type : 'ajax', // Ext.data.proxy.Ajax 
     api : { 
      create : 'api/management/employees.create.php', 
      read : 'api/management/employees.read.php', 
      update : 'api/management/employees.update.php', 
      destroy : 'api/management/employees.destroy.php' 
     }, 
     reader : { 
      type   : 'json', // Ext.data.reader.Json 
      rootProperty : 'records' 
     }, 
     writer : { 
      type   : 'json', // Ext.data.writer.Json 
      encode  : true, 
      rootProperty : 'record' 
     } 
    } 
}); 

在窗口的呼叫,該複選框是選中和過濾器是活動的,因爲電網聽衆是:

listeners: { 
     render: function() { 
      this.getStore().load(); 
      this.getStore().rightFilter(); // <<<<< if the function is called here, the problem exists, if not, the filter works perfectly ! 
     } 
    }, 

我第一次選中複選框過濾器被正確清除,並且控制檯中出現'clearFilter'消息。當我取消選中時,消息'rightFilter'也出現,但過濾器在網格中沒有任何東西......並且出現錯誤消息「Uncaught TypeError:Can not read property'get'of undefined」。

我在哪裏錯了?

編輯:其實過濾功能只能正常工作一次。在clearFilter被稱爲...
後,它不再工作,我用addFilter/removeFilter嘗試,結果相同。
我的下一次嘗試將是setDisable
如果有人有任何(其他)的想法...

編輯2:測試用例in fiddle
現在我知道,這個問題是來自函數調用的渲染功能。當這個調用沒有完成時,該複選框完美地工作,但是在顯示時,複選框狀態不對應於顯示,並且我想隱藏過濾項目。

任何想法?

+0

您需要發佈測試用例。 –

+0

可能是疏忽大意,但是您是否已將商店添加到控制器類中?或者可能是你的這個。('window')。getComponent失敗。 – aMazing

+0

控制器不需要訪問商店。實際上變量'store'(this.up('window')...)很好地指向了網格商店。 – Michel

回答

1

的主叫過濾功能不能被調用在加載之後,這就是爲什麼在視圖中加載渲染和過濾的原因(在渲染後它也不起作用)。問題已經解決了 !!

listeners: { 
     render: function() { 
      this.getStore().load(); 
     }, 
     viewready: function() { 
      this.getStore().rightFilter(); 
     } 
    } 
0

問題是在這一行是這個

rightFilter: function() { 
     this.filterBy(function(record) { // <<<<< this line sends an error the second time the function is called 
      return record.get('rights') >= 0; 
     }); 
    }, 

能否請你上面的代碼更改爲

rightFilter: function(me) { 
me.filterBy(function(record) { // <<<<< this line sends an error the second time the function is called 
return record.get('rights') >= 0; 
}); 
}, 

和電網聽衆傳遞店

listeners: { 
     render: function() { 
      this.getStore().load(); 
      this.getStore().rightFilter(this.getStore()); 
     } 
    }, 

,並從組合框

if (newValue) { 
       console.log('clearFilter'); 
       store.clearFilter(); 
      } else { 
       console.log('rightFilter'); 
       store.rightFilter(store); 
      } 
+0

我試過這個解決方案,它沒有幫助。感謝您的提示。 – Michel

相關問題