无法访问Ext.form.field.Types中的字段

时间:2014-04-02 08:26:02

标签: extjs4

此代码正常运行:

    Ext.application({
    name: 'WebClient',
    autoCreateViewport: true,
    launch: function() {                
        Ext.apply(Ext.form.field.VTypes, {
            IPAddress:  function(v) {
                return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
            },
            IPAddressText: 'Некорректный IP Адресс',
            IPAddressMask: /[\d\.]/i
        });

        Ext.apply(Ext.form.field.VTypes, {
            port:  function(v) {
                function isNumber(n) {
                  return !isNaN(parseFloat(n)) && isFinite(n);
                }
                if (!isNumber(v)) return false;
                return (v>=0 && v<=65535)
            },
            portText: 'Порт 2 байта 0..65535',
            portMask: /[\d\.]/i
        });

    },
    models: ['Request','RPCLog','Connection']
});

但是,如果我对行autoCreateViewport: true发表评论,或将此属性设置为false,则浏览器会产生错误:Uncaught TypeError: Cannot read property 'field' of undefined。如何在没有Ext.form.field.VTypes的情况下提供autoCreateViewport:true

1 个答案:

答案 0 :(得分:0)

我有同样的问题,除了我在视图中定义自定义VType。

在initComponent中定义VType有助于解决问题。

initComponent : function(){

        // Add the additional 'advanced' VTypes

        Ext.apply(Ext.form.field.VTypes, {
            daterange: function(val, field) {