这是我的json:
[{"node":
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.',
'age': 1}},
{"node":{'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.',
'age': 2}},
{"node":{'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.',
'age': 3}}
];
这是我的代码:
Search-title: <input type='text' ng-model="name">
<div class='cat' ng-repeat="(key,value) in phones ">
<ul ng-repeat="fin in value | filter:name ">
<li><h3>{{fin.name}}</h3>
{{fin.snippet}}
</li>
</ul>
</div>
如何为此json对象应用过滤器?
答案 0 :(得分:1)
请看到此处:http://jsbin.com/kovegi/1/edit?html,js,output CodingNinja已关闭,只需使用ng-model="searchObj.node.name"
代替ng-model="searchObj.name"
<div ng-controller="firstCtrl">
Search-title: <input type='text' ng-model="searchObj.node.name">
<div class='cat' ng-repeat="(key,value) in phones | filter:searchObj ">
<ul ng-repeat="fin in value">
<li><h3>{{fin.name}}</h3>
{{fin.snippet}}
</li>
</ul>
</div>
答案 1 :(得分:0)
不是直接在过滤器中使用模型,而是将其设为对象并将值设置在同一变量中,然后在搜索中使用它
Search-title: <input type='text' ng-model="searchObj.node">
<div class='cat' ng-repeat="(key,value) in phones | filter:searchObj">
<ul ng-repeat="fin in value">
<li><h3>{{fin.name}}</h3>
{{fin.snippet}}
</li>
</ul>
</div>