2

我已经编写了如下的自定义验证

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 文件会在所有验证之后变得很大。

4

2 回答 2

2

根据文档,您可以创建一个覆盖,例如:

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"
  ],
于 2016-06-28T05:40:30.737 回答
0

根据@CD ..

1)我在我的应用程序中找到了overrides文件夹

2) 将此VTypes.js文件放在覆盖文件夹的根目录中:

Ext.override(Ext.form.field.VTypes, {
    digitsOnly: function (value) {
        return this.digitsOnlyRe.test(value);
    },
    digitsOnlyRe: /\\d*$/,
    digitsOnlyText: 'Use digits only!'
});

现在一切正常,谢谢

于 2020-02-17T10:06:01.283 回答