我正在为我的网站创建一个插件。我的目的是从网站获取一些数据并将其编译成对象。
然后,当文本输入可编辑范围时,我将对这些对象进行搜索。但是,每当我输入数据时,似乎都没有调用test
方法。有什么想法吗?
var MarvSearch = function(elm, options) {
this.element = elm;
this.options = jQuery.extend({}, this.defaults, options);
this.makes = null;
this.models = null;
this.init();
}; MarvSearch.prototype = {
init: function() {
var $models = [], $makes = [];
// Filter model array into objects
$(modelItems).each(function() {
var $num = $(this)[2].match(/\((.*)\)/)[1],
$title = ($(this)[2].replace(/\((.*)\)/, '')).trim(),
$entry = { 'makeID': $(this)[0], 'modelID': $(this)[1], 'title': $title, 'num': $num };
$models.push($entry);
});
// Filter make select options into array
$('#make option').each(function() {
if ($(this).val() !== '')
$makes.push({
makeID: $(this).val(),
title: ($(this).text()).replace(/\((.*)\)/, '').trim(),
num: $(this).text().match(/\((.*)\)/)[1]
});
});
this.models = $models;
this.makes = $makes;
},
defaults: {
},
attach: function() {
var self = this;
JQuery(this.element).bind({
'change.MarvSearch': function(){ self.test(this.element); },
'keyup.MarvSearch': function(){ self.test(this.element); }
});
},
test: function() {
console.log(this.element);
}
};
var MarvSearch = new MarvSearch(document.getElementById('marv-search'));