diff --git a/filter.js b/filter.js index d832faf..c53c340 100644 --- a/filter.js +++ b/filter.js @@ -274,7 +274,12 @@ var vals = []; criteria.$ele.filter(criteria.selector).each(function() { - vals.push($(this).val()); + var value = $(this).val(); + if (value instanceof Array) { + vals = vals.concat(value); + } else { + vals.push(value); + } }); if(criteria.type == 'range'){ @@ -325,7 +330,7 @@ //Search var bindSearchEvent = function(searchBox, timeout, context){ - $('body').on('keyup', searchBox, function(e){ + var handler = function(e){ if (context.searchTimeoutId) { clearTimeout(context.searchTimeoutId); } @@ -333,7 +338,15 @@ context.filter(); }, timeout); //context.searchFilter(true); - }); + }; + $('body').on('keyup', searchBox, handler); + return handler; + }; + + var unbindSearchEvent = function(searchBox, handler){ + if (handler) { + $('body').off('keyup', searchBox, handler); + } }; F.initSearch = function(opts){ @@ -350,7 +363,8 @@ if(this.$search_ele.length){ this.has_search = true; this.searchFn = this.buildSearchFn(opts.fields); - bindSearchEvent(opts.ele, opts.timeout || 0, this); + unbindSearchEvent(opts.ele, this.searchHandler); + this.searchHandler = bindSearchEvent(opts.ele, opts.timeout || 0, this); } };