我正在尝试使用自定义 vtype 验证文本字段以过滤空格,例如:“”。 我在 app.js 中定义了我的自定义 vtype(我使用的是 mvc 模式)。
Ext.Loader.setConfig({
enabled : true,
paths: {
Ext: 'vendor/ext41/src',
My: 'app'
}
});
Ext.apply(Ext.form.field.VTypes, {
descartarBlanco: function(value) {
return /^\s+$/.test(value);
}
});
Ext.application({
name: 'CRUDManantiales',
appFolder: 'app',
controllers: ['Ui','Usuarios'],
....
});
但是,Firebug 显示这个错误:
TypeError: vtypes[vtype] is not a function
我认为语法是正确的。但是,我不知道在哪里插入 Vtype 的代码。 任何想法 ?。 谢谢。
最佳答案
我将我的自定义 vtypes 放在我的应用程序的 Controller 中,在渲染表单之前。
Ext.define('MyApp.controller.Main', {
extend: 'Ext.app.Controller',
...
init: function () {
var me = this;
me.control({
...
'form': {
beforerender: this.applyVtypes
},
...
})
},
...
applyVtypes: function() {
Ext.apply(Ext.form.field.VTypes, {
descartarBlanco: function(value) {
return /^\s+$/.test(value);
}
}
}
...
}
关于javascript - Extjs 自定义 vtype,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13417268/