2013-08-26 65 views
5

我有問題,我的控制器EXTJS 4.2參數在聽衆功能

Ext.define('app.controller.myController', { 
    init: function() { 
     this.control({ 
      '#myinputfield': { 
       change: this.textFieldChange(parameter) 
      } 
     }) 
    }, 
    textFieldChange: function(parameter) { 
     //do something 
    } 
}); 

它的外觀像這樣 的問題是,當我的網站後,給這裏的參數

change: this.textFieldChange(parameter) 

那麼它火起來了負載,我不知道爲什麼。

沒有參數它的等待更改事件像它應該 可以any1幫助我嗎?

回答

7

這是因爲:

change: this.textFieldChange這裏你給這個屬性

change: this.textFieldChange(parameter)這裏你給了結果的功能這個屬性(這個函數的引用它,如果我們不」 t使用return,那麼它將是undefined)。

可以使用eOpts變量的函數定義,自定義參數發送,請參閱實例:

Ext.define('app.controller.myController', { 
    init: function() { 
     this.control({ 
      '#myinputfield': { 
       change: { 
        fn : this.textFieldChange, 
        params : { 
         param1: 'something' 
        } 
       } 
      } 
     }) 
    }, 
    textFieldChange: function(textfield, newValue, oldValue, eOpts) { 
     var params = eOpts.params; 
     console.log(params.param1); 
     //do something 
    } 
});