2016-06-28 39 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'文件夾中提取文件.. –