Browse Source

fix filterBy multiple keys (fix #1479)

Evan You 10 years ago
parent
commit
27bb331169
2 changed files with 5 additions and 4 deletions
  1. 3 4
      src/filters/array-filters.js
  2. 2 0
      test/unit/specs/filters/filters_spec.js

+ 3 - 4
src/filters/array-filters.js

@@ -39,12 +39,11 @@ exports.filterBy = function (arr, search, delimiter /* ...dataKeys */) {
         if ((key === '$key' && contains(item.$key, search)) ||
             contains(Path.get(val, key), search)) {
           res.push(item)
+          break
         }
       }
-    } else {
-      if (contains(item, search)) {
-        res.push(item)
-      }
+    } else if (contains(item, search)) {
+      res.push(item)
     }
   }
   return res

+ 2 - 0
test/unit/specs/filters/filters_spec.js

@@ -151,6 +151,8 @@ describe('Filters', function () {
     ]
     // multiple string keys
     var res
+    res = filter(arr, '', 'in', 'firstname', 'lastname')
+    assertArray(res, [arr[0], arr[1], arr[2]])
     res = filter(arr, 'A', 'in', 'firstname', 'lastname')
     assertArray(res, [arr[0], arr[2]])
     // array of keys