1
我使用一個jQuery插件,做一個頁面上的搜索:http://rmm5t.github.io/jquery-sieve/jQuery的搜索插件,顯示沒有結果
它的偉大工程,但我試圖找出我將如何去了解它更新到如果搜索沒有返回任何內容,則顯示「無結果」。我知道我需要它來隱藏,但是這怎麼就我已經得到了...
(function() {
var $;
$ = jQuery;
$.fn.sieve = function(options) {
var compact;
compact = function(array) {
var item, _i, _len, _results;
_results = [];
for (_i = 0, _len = array.length; _i < _len; _i++) {
item = array[_i];
if (item) {
_results.push(item);
}
}
return _results;
};
return this.each(function() {
var container, searchBar, settings;
container = $(this);
settings = $.extend({
searchInput: null,
searchTemplate: "<div><label>Search: <input type='text'></label></div>",
itemSelector: "tbody tr",
textSelector: null,
toggle: function(item, match) {
return item.toggle(match);
},
complete: function() {}
}, options);
if (!settings.searchInput) {
searchBar = $(settings.searchTemplate);
settings.searchInput = searchBar.find("input");
container.before(searchBar);
}
return settings.searchInput.on("keyup.sieve change.sieve", function() {
var items, query;
query = compact($(this).val().toLowerCase().split(/\s+/));
items = container.find(settings.itemSelector);
items.each(function() {
var cells, item, match, q, text, _i, _len;
item = $(this);
if (settings.textSelector) {
cells = item.find(settings.textSelector);
text = cells.text().toLowerCase();
} else {
text = item.text().toLowerCase();
}
match = true;
for (_i = 0, _len = query.length; _i < _len; _i++) {
q = query[_i];
match && (match = text.indexOf(q) >= 0);
}
return settings.toggle(item, match);
});
return settings.complete();
});
});
};
}).call(this);
絕對是我在找的!謝謝! – user1555843