在ExtJS中,我可以通过vtype传递参数吗? [英] In ExtJS, Can I pass argument via vtype?

查看:142
本文介绍了在ExtJS中,我可以通过vtype传递参数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到通过vtype传递参数的方式。

所以我做一些onfly vtype函数。

I can't find the way to pass argument via vtype.
So I do some onfly vtype function.

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'
    });
}

当我想设置vtype时,我应该首先调用这个函数。 / p>

And when I want to set vtype, I should call this function first.

vtypeMaker(10);
myTextfield.vtype = 'myTest';

它工作但代码太长。

任何人都有更好的主意?

It works but too long code.
Anyone has better idea ?

谢谢。

推荐答案

使用验证器 config来传递一个自定义的验证器功能,并使用 createDelegate 自定义要发送给它的参数:

Use the validator config to pass a custom validator function and use createDelegate to customize the parameters that will be sent to it:

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 将导致这些自定义参数附加到函数调用的参数(在本例中为字段值)。

The custom parameters are set in the second parameter to createDelegate. Setting the third parameter to true will result in those custom parameters being appended to the parameters the function was called with (in this case, the field value).

这篇关于在ExtJS中,我可以通过vtype传递参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆