Index: ssts-web/src/main/webapp/js/Ext4CompUtil.js =================================================================== diff -u --- ssts-web/src/main/webapp/js/Ext4CompUtil.js (revision 0) +++ ssts-web/src/main/webapp/js/Ext4CompUtil.js (revision 15527) @@ -0,0 +1,92 @@ +/** + * extJS4组件工具类,用来创建组件 + */ +var ext4CompUtil = (function () { + /** + * extJS4组件工具类工厂,用来返回需要创建的对象,以后扩展可以通过增加对应的组件对象,然后用这个工厂返回(参考comboBuilder) + * @constructor + */ + var Ext4CompUtilFactory = function () { + this.getComboBuilder = function () { + return comboBuilder; + } + } + + //region comboBuilder + + //用来创建combo对象 + var comboBuilder = {}; + + /** + * 创建并获得combo的数据源,默认通过ajax的方式来请求远程的数据 + * @param storeConfig 相关的配置(必传:url,model;可选:autoLoad) + * @returns {Ext.data.Store} + */ + comboBuilder.getStore = function (storeConfig) { + var store = Ext4.create('Ext.data.Store', { + model: storeConfig.model, + proxy: { + type: 'ajax', + url: storeConfig.url, + reader: { + type: 'json', + root: 'data', + totalProperty: 'totalCount' + } + }, + autoLoad: storeConfig.autoLoad || false + }); + return store; + } + + /** + * 创建并获得combo对象 + * @param comboConfig 相关的配置 + * 1.(必选:store,valueField,displayField,fieldLabel,id,name) + * 2.(可选:width,allowBlank,listeners) + * @returns {Ext4.form.ComboBox} + */ + comboBuilder.getCombo = function (comboConfig) { + var combo = Ext4.create('Ext4.form.ComboBox', { + store: comboConfig.store, + valueField: comboConfig.valueField, + displayField: comboConfig.displayField, + fieldLabel: comboConfig.fieldLabel, + id: comboConfig.id, + name: comboConfig.name, + queryParam: 'spell', + triggerAction: 'all', + minChars: 0, + width: comboConfig.width || 600, + forceSelection: true, + lazyInit: true, + triggerAction: 'all', + hideTrigger: true, + typeAhead: false, + allowBlank: comboConfig.allowBlank || true, + anchor: '97%', + listeners: comboConfig.listeners || { + select: function (combo, records, eOpts) { + } + } + }); + return combo; + } + + /** + * 直接通过storeConfig和comboConfig来获得combo对象 + * @param config 里面要有storeConfig配置和comboConfig配置 + * @returns {Ext4.form.ComboBox} + */ + comboBuilder.createCombo = function (config) { + var me = this; + var store = me.getStore(config.storeConfig); + config.comboConfig.store = store; + var combo = me.getCombo(config.comboConfig); + return combo; + } + //endregion + + return new Ext4CompUtilFactory(); + +})(); \ No newline at end of file