【发布时间】:2017-04-16 11:21:55
【问题描述】:
对象:
Object
$$hashKey: "object:25"
id: 1
category: "Fruit"
name: "Apple"
color: "red"
__proto__: Object
Javascript(咖啡脚本):
$scope.fruits = [
{id: 1, category: "Fruit", name: "Apple", color: "red"}
]
HTML:
<input type="search" ng-model="fruitSearch"/>
<div ng-repeat="i in filtro = (fruits | scFilter:fruitSearch)">
<div>{{i.id}}</div>
<div>{{i.category}}</div>
<div>{{i.name}}</div>
<div>{{i.color}}</div>
</div>
过滤代码(js/coffee)
.filter "scFilter", () ->
(collection, search) ->
if search
regexp = createAccentRegexp(search)
doesMatch = (txt) ->
(''+txt).match(regexp)
collection.filter (el) ->
if typeof el == 'object'
return true for att, value of el when (typeof value == 'string') && doesMatch(value)
doesMatch(el)
false
else
collection
所以我想要在这里只过滤显示的元素(id、类别、名称和颜色),但由于某种原因,当我在输入中键入 25 时,由于他的 $$haskKey,该对象仍然显示。
【问题讨论】:
-
请提供您的过滤器代码,如果您使用的是图书馆中已有的,请提供描述/链接/文档
-
添加了过滤代码。
标签: javascript html angularjs coffeescript