在ExtJS中,我可以通过vtype传递参数吗?

在ExtJS中,我可以通过vtype传递参数吗?,extjs,Extjs,我找不到通过vtype传递参数的方法。 所以我做了一些onfly vtype函数 var vtypeMaker = function(n){ Ext.apply(Ext.form.VTypes, { myTest : function(v, o){ console.debug(n); // <-- I can pass my custom value // do something // ...

我找不到通过vtype传递参数的方法。
所以我做了一些onfly vtype函数

var vtypeMaker = function(n){
    Ext.apply(Ext.form.VTypes, {
        myTest : function(v, o){
            console.debug(n); // <-- I can pass my custom value
            // do something
            // ...
            return myRegex.test(v);
        },
        myTestText : 'some message'
    });
}
它可以工作,但代码太长。
谁有更好的主意


谢谢。

使用验证程序配置传递自定义验证程序函数,并使用createDelegate自定义将发送给它的参数:

var myValidator = function( value, custom ) {
    if ( /* value is valid */ ) {
        return true;
    }
    else {
        return 'Field value is not valid';
    }
};

new Ext.form.TextField({
    fieldLabel: 'A text field',
    validator: myValidator.createDelegate(null, [10], true);
});

new Ext.form.TextField({
    fieldLabel: 'Another text field',
    validator: myValidator.createDelegate(null, [14], true);
});

自定义参数在第二个参数中设置为createDelegate。将第三个参数设置为true将导致这些自定义参数附加到调用函数的参数(在本例中为字段值)。

为什么需要动态创建vtype?
var myValidator = function( value, custom ) {
    if ( /* value is valid */ ) {
        return true;
    }
    else {
        return 'Field value is not valid';
    }
};

new Ext.form.TextField({
    fieldLabel: 'A text field',
    validator: myValidator.createDelegate(null, [10], true);
});

new Ext.form.TextField({
    fieldLabel: 'Another text field',
    validator: myValidator.createDelegate(null, [14], true);
});