2012-04-02 137 views
0

如何定義texfield驗證器範圍? 我在控制器定義驗證器與該代碼:extjs驗證器範圍

this.editView.getRegNumberTextField().validator = this.regNumberValidator; 
//... 
regNumberValidator:function (input) { 
//validation here 
} 

但是,在這種情況下,在功能regNumberValidator範圍RegNumberTextField。我希望它成爲Controller範圍。我用{scope:this}嘗試了Ext.apply,但它沒有幫助。應該有一些方法來定義範圍,如在on('event',handler, scope)聲明中。

回答

0

我的問題的解決方案是Ext.bind 的代碼是:

this.editView.getRegNumberTextField().validator = Ext.bind(this.regNumberValidator,this); 
-1

你只需要創建一個委託:

this.editView.getRegNumberTextField().validator = this.regNumberValidator.createDelegate(this); 

//... 

regNumberValidator:function (input) { 
//validation here 
} 
+0

否代表在第4版中 – 2012-04-06 18:03:04

1

簡單地定義「控制器」字段屬性,如您控制器,然後您將通過this.getController()訪問驗證器中的控制器範圍:

xtype: 'combo', 
controller: 'mycontrolleralias', 
validator : function() { 
    return this.getValue() === this.getController().getViewModel().get('record').getId()? 
             'Affiliate cannot be the parent of itself':true; 
}