我要过滤这个数组:
Ricette: [{
"id":"1",
"title":"Pasta al pomodoro",
"ings":{"id":["1","2","3"]}
}, {
"id":"2",
"title":"Spaghetti alla carbonara",
"ings":{"id":["1","2","4","5","6"]}
}]
我需要按照从复选框
中选择的ings
进行过滤
ings
列表:
[{"id":"1","nome":"Olio"},
{"id":"2","nome":"Pasta"},
{"id":"3","nome":"Passata di pomodoro"},
{"id":"4","nome":"Parmigiano"},
{"id":"5","nome":"Uova"},
{"id":"6","nome":"Pancetta"}]
模板:
<div ng-repeat="ing in ingredienti">
<b><input type="checkbox">{{ing.nome}}</b>
</div>
<ion-list>
<ion-item ng-repeat="ricetta in ricette" href="#/app/ricette/{{ricetta.id}}">
{{ricetta.title}}
</ion-item>
</ion-list>
我如何过滤&#34; ricette&#34;按所选复选框列出?
答案 0 :(得分:0)
您需要一种方法来跟踪实际检查的复选框。我会像'ng-model'那样:
<div ng-repeat="ing in ingredienti">
<b><input type="checkbox" ng-model="ing.checked">{{ing.nome}}</b>
</div>
<ion-list>
<ion-item ng-repeat="ricetta in ricette" href="#/app/ricette/{{ricetta.id}}">
{{ricetta.title}}
</ion-item>
</ion-list>
然后您的过滤器就像:ingredienti | filter:{checked:true}