我正在编写一个jQuery插件,并且想在同一页面上多次使用它。我有一个AJAX请求来获取一些数据,然后更新插件的选项,但是在我初始化插件后,所有插件实例的选项都相同。
q = Q('bool', should=[Q('match', **{key:value})])
var AliFile = function(el, options) {
this.options = $.extend(true, $.fn.aliFile.defaults, options);
this.getAliOptions();
};
AliFile.prototype.getAliOptions = function() {
var self = this;
utils.getAliOptions(this.options).done(function(response) {
console.log(self.options);
if (response.status == 200) {
self.options.maxSize = response.custom_limit.content_length_range.max;
self.options.types = response.custom_limit.type;
self.options.url = response.host;
}
}).fail(function(error) {
console.log(error);
});
};
$.fn.aliFile = function(options) {
return this.each(function() {
new AliFile($(this), options)
});
};
$('.s-file-input').aliFile({
space: 'kmf-image',
subject: 'test-yunying-image',
product_line: 'yunying',
maxLength: 15,
selectors: {
hiddenInput: '.image-url',
uploadButton: '.s-file-select'
},
});
$('.s-doc-input').aliFile({
space: 'kmf-doc',
subject: 'test-yunying-material',
product_line: 'yunying',
multiple: true,
maxLength: 1,
selectors: {
hiddenInput: '.doc-url',
uploadButton: '.s-doc-select'
},
})
的输出是相同的。