2012-04-02 123 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; 
}