2016-06-28 103 views
1

我已经写了自定义的验证像下面制作自定义验证在EXTJS为

Ext.apply(Ext.form.field.VTypes, { 
    valInt: function(v) { 
     return /^(\d+(,\d+)*)?$/.test(v); 
    }, 
    valIntText: 'Must be in the form #,#', 
    valIntMask: /[\d\,]/i 
}); 

它的工作原理组件。但我想在单个文件中进行所有这些自定义验证,然后加载它或自动加载它。我该怎么做?

我可以像下面app.js

Ext.onReady(function() {  
    Ext.apply(Ext.form.field.VTypes, { 
     valInt: function(v) { 
      return /^(\d+(,\d+)*)?$/.test(v); 
     }, 
     valIntText: 'Must be in the form #,#', 
     valIntMask: /[\d\,]/i 
    }); 
}); 

但随后的app.js文件将成为所有验证后大。

回答

1

按照documentation你可以创建一个覆盖,如:

Ext.define('Override.form.field.VTypes', { 
    override: 'Ext.form.field.VTypes', 

    valInt: function(v) { 
     return /^(\d+(,\d+)*)?$/.test(v); 
    }, 

    valIntText: 'Must be in the form #,#', 

    valIntMask: /[\d\,]/i 
}); 

在你的app.json有声明倍率目录一overrides关键,它看起来像:

/** 
    * Comma-separated string with the paths of directories or files to search. Any classes 
    * declared in these locations will be automatically required and included in the build. 
    * If any file defines an Ext JS override (using Ext.define with an "override" property), 
    * that override will in fact only be included in the build if the target class specified 
    * in the "override" property is also included. 
    */ 
    "overrides": [ 
    "overrides", 
    "${toolkit.name}/overrides" 
    ], 
+0

我为此创建了一个不同的文件并添加了上面的代码。但是当我尝试在我的字段中使用像vtype:'valInt'时,它像Uncaught TypeError一样说:vtypes [vtype]不是函数 – Hacker

+0

如何使该文件/组件可用? – Hacker

+0

您是否使用'Sencha CMD',它应该从'override'文件夹中提取文件.. –