/** * Created by jinxs on 14-8-19. */ (function ($) { /** * 缓存名称 * @type {string} * @private */ var _cacheName = 'uiDictCombobox'; /** * @class 数据字典下拉框 * @extends uiCombo * @requires {@link uiCombo} * @constructor uiCombobox * @summary 构造函数 * @param [options] {Object|String} 组件配置参数|要调用的组件方法名 * @param [param] {Object} 表示要调用的组件方法的参数 * @example * // 构件组件 * $('#selectAge').dictCombobox({direction: 'left'}); * // 调用组件方法options * $('#selectAge').dictCombobox("options"); */ $.fn.dictCombobox = function (options, param) { if (typeof options == 'string') { var method = $.fn.dictCombobox.methods[options]; if (method) { return method(this, param); }else { return $(this).uiCombobox(options,param); } } return this.each(function () { var me = $(this); var state = me.data(_cacheName); options = options || {}; if (state) { $.extend(state.options, options); } else { state = { options: $.extend({}, $.fn.dictCombobox.defaults, me.parseUIConfig(), options), data: [] }; me.data(_cacheName, state); } _init(me); }); }; /** * 方法 * @lends uiCombobox.prototype */ $.fn.dictCombobox.methods = $.fn.uiCombobox.defaults; $.fn.dictCombobox.defaults = $.extend({}, $.fn.uiCombobox.defaults, /** * 默认配置 * @lends uiCombobox.prototype */ { /** * @type String * @default "value" * @summary 组件数据"值"字段 */ valueField: 'value', /** * @type String * @default "text" * @summary 组件数据"文本"字段 */ textField: 'name', /** * 字典key */ dictKey: '', /** * 是否缓存数据 */ cache: true }); var _init = function (target) { var state = $.data(target[0], _cacheName); var opts = state.options; var hdName = dict_prefix + opts.dictKey; if (window[hdName] && opts.cache) { opts.mode = 'local'; opts.data = window[hdName]; } else { opts.url = 'remote'; opts.url = dictBaseUrl + opts.dictKey; opts.onLoadSuccess = function (data) { window[hdName]=data; } } target.uiCombobox(opts); } })(jQuery);