Fixes logic error in filter search

The search was using !$.inArray when the expression should be $.inArray === -1 since it returns the index of the value in the array.
Also tidied up the code so it is easier to read.
Fixes #1918
This commit is contained in:
Samuel Georges 2016-06-11 15:09:08 +10:00
parent d1b765fa5e
commit 04c4fe9633
2 changed files with 8 additions and 11 deletions

View File

@ -302,15 +302,13 @@
* Ensure any active items do not appear in the search results
*/
if (items.active.length) {
var compareFunc = function(a, b) { return a.id == b.id },
inArrayFunc = function(elem, array, testFunc) {
var i = array.length
do { if (i-- === 0) return i } while (testFunc(array[i], elem))
return i
}
var activeIds = []
$.each(items.active, function (key, obj) {
activeIds.push(obj.id)
})
filtered = $.grep(available, function(item) {
return !inArrayFunc(item, items.active, compareFunc)
return $.inArray(item.id, activeIds) === -1
})
}
else {

View File

@ -2974,10 +2974,9 @@ if(!this.scopeValues[this.activeScopeName])
return
var
self=this,filtered=[],items=this.scopeValues[scopeName]
if(items.active.length){var compareFunc=function(a,b){return a.id==b.id},inArrayFunc=function(elem,array,testFunc){var i=array.length
do{if(i--===0)return i}while(testFunc(array[i],elem))
return i}
filtered=$.grep(available,function(item){return!inArrayFunc(item,items.active,compareFunc)})}
if(items.active.length){var activeIds=[]
$.each(items.active,function(key,obj){activeIds.push(obj.id)})
filtered=$.grep(available,function(item){return $.inArray(item.id,activeIds)===-1})}
else{filtered=available}
var container=$('#controlFilterPopover .filter-items > ul').empty()
self.addItemsToListElement(container,filtered)}