2011-06-07 52 views
0

我是新來Extjs庫,我不知道如何添加偵聽器到GridPanel中的一些事件。當我以異步方式填充網格時,我希望在將新元素添加到網格面板時執行我的函數。Extjs4和綁定函數GridPanel中的事件

我發現(我認爲)正確的事件:

added(Ext.Component this, Ext.container.Container container, Number pos) 

,但如在頁面加載只執行一次這個功能我不能找到一個正確的地方把聽衆:

Ext.define('MyApp.NewsGrid', { 
    extend: 'Ext.grid.GridPanel', 
    alias: 'widget.newsgrid', 
    initComponent: function() { 
    Ext.apply(this, { 
     title: 'News', 
     store: newsStore, 
     viewConfig: { 
     plugins: [{ 
      pluginId: 'preview', 
      ptype: 'preview', 
      bodyField: 'testo', 
      expanded: false 
     }], 
     listeners: { 
      add: function() { 
      alert("add executed"); 
      }, 
      added: function() { 
      alert("added executed"); 
      } 
     } 
     }, 
.... 

問題是添加監聽器有多種不同的方法(viewConfig hash內部和外部,組件內部和外部定義等),我無法弄清楚這種情況下的工作。更令人沮喪的是,互聯網上有很多地方都有版本3的文檔,甚至沒有指定版本。

+0

要補充什麼元素還是你的意思是你要聽,當新的記錄被添加到底層商店? – 2011-06-07 16:01:58

+0

像@amol說的,..如果是這樣,請嘗試在您的商店中添加監聽器..不在網格中 – 2011-06-07 17:52:09

回答

4

你應該聽的add事件商店:

initComponent: function() { 
    // somewhere inside initComponent... 
    this.getStore().on("add", function(store, records) { 
     alert(records.length + " records added"); 
    }, this); 
} 
相關問題