2012-08-22 105 views
0

這是我在網格內組合框的代碼。afterrender在EXTJS網格中使用組合框時不起作用

{ 
    header: 'FSCS', 
    dataIndex: 'acntOvrrideTypeCd', 
    flex: 1, 
    renderer: function(val, metaData, record, rowIndex, colIndex) { 
     var id = Ext.id(); 
     var store = new Ext.data.Store({ 
      fields: ['code', 'description'], 
      data: [{ 
       "code": "", 
       "description": "" 
      }, { 
       "code": "E", 
       "description": "E" 
      }, { 
       "code": "D", 
       "description": "D" 
      }, { 
       "code": "S", 
       "description": "S" 
      }] 
     }); 

     Ext.Function.defer(
      (function() { 
       var cb = Ext.create('Ext.form.ComboBox', { 
        id: 'acntOvrrideTypeCd-' + rowIndex, 
        queryMode: 'local', 
        renderTo: id, 
        store: store, 
        forceSelection: true, 
        triggerAction: 'all', 
        lazyRender: true, 
        size: 5, 
        valueField: 'code', 
        displayField: 'description', 
        value: val 
        //listeners:{ 
        // scope: this, 
        // 'select': Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex) 
        //} 

       }); 
       cb.on(afterrender, function() { 
        console.log("------- box---" + rowIndex); 
        Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex); 
       }); 
      }), 0.25); 

     console.log("i----------" + id); 
     return (Ext.String.format('<div id="{0}"></div>', id)); 
    } 
} 

「afterrender」事件未被解僱。我需要在渲染後啓用或禁用組件。

任何人都可以幫忙。

回答

0

這只是一個錯字,afterrender應該在引號中,否則您只會添加未定義事件的函數。

cb.on('afterrender',function(){ 
    console.log("------- box---" + rowIndex); 
    Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex); 
}); 
0

您的代碼有幾個問題。

  1. 它看起來像你想創建一個網格的渲染功能的組合框(代碼頂部沒有得到包括在代碼塊)。你最好使用Ext.grid.plugin.CellEditing插件,它會根據需求創建一個字段,而不是在列呈現時。另外,每當網格視圖刷新時,您將爲網格中的每一行創建另一個存儲區和組合框。性能不佳,對用戶體驗也不利。

  2. 當調用延遲時,持續時間以毫秒爲單位,而不是秒。另外,您不需要將函數包裝在括號中。只需給它自己的功能。就像這樣:

    Ext.defer(function(){ 
        // do stuff 
    }, 25); 
    
  3. 設置lazyRender爲true,只有當你的組件是一些容器,它不會立即呈現其所有組件(如一個tabpanel)的子工程。

  4. 創建組合框時,只需在組合框中設置禁用的配置,而不是在創建時,可能會更容易,除非在創建時沒有可用的信息。

  5. 像nscrob所說的,當使用on方法時,您需要將事件指定爲字符串。如果您使用監聽器的配置(您已註釋掉),你可以這樣做:

    listeners: { 
        afterrender: function(){ 
         console.log("------- box---" + rowIndex); 
         Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex); 
        }, 
        select: function(){ 
         Ext.getCmp('amlFscsForm').controller.amlShow(rowIndex); 
        } 
    } 
    

    需要注意的是這些監聽功能的默認組件本身(你的組合框)的範圍,以便scope: this是不必要的很重要。除非你希望範圍是任何對象創建這個組合框,那就是。

第一點是最重要的。看看使用CellEditing(或RowEditing)插件,我保證事情會更順利。

相關問題