【发布时间】:2014-07-29 06:08:11
【问题描述】:
我有一个 json 酒单,我的愿望是用 AngularJS 构建一个代码来过滤结果
json 文件
[
{ "name": "Wine a", "type": "red", "country": "france", "style": "strong" },
{ "name": "Wine a", "type": "white", "country": "italie", "style": "medium" },
{ "name": "Wine a", "type": "white", "country": "france", "style": "light" },
{ "name": "Wine a", "type": "rose", "country": "usa", "style": "strong" },
{ "name": "Wine a", "type": "champagne", "country": "chili", "style": "medium" },
{ "name": "Wine a", "type": "red", "country": "brazil", "style": "strong" },
{ "name": "Wine a", "type": "red", "country": "france", "style": "strong" }
]
复选框
<div ng-controller="MainCtrl">
<input ng-model="red" type="checkbox" >red</input>
<input ng-model="white" type="checkbox" >white</input>
<input ng-model="rose" type="checkbox" >rose</input>
<input ng-model="champagne" type="checkbox" >champagne</input>
<input ng-model="france" type="checkbox" >france/input>
<input ng-model="italie" type="checkbox" >italie</input>
<input ng-model="brazil" type="checkbox" >brazil</input>
<input ng-model="chili" type="checkbox" >chili</input>
<input ng-model="strong" type="checkbox" >strong</input>
<input ng-model="medium" type="checkbox" >medium</input>
<input ng-model="light" type="checkbox" >light</input>
</div>
我的愿望
我的愿望是建立一个动态的多参数过滤器列表,列表的结果将与复选框的值匹配。
如果我检查红色和烈性,将出现在列表中,只有带有这些参数的 json 列表中的葡萄酒(红色和烈性葡萄酒的列表)。
如果我检查红色、白色和法国,将出现在列表中,只有带有这些参数的 json 列表中的葡萄酒(法国红葡萄酒和白葡萄酒的列表)。
我尝试了许多解决方案,但没有结果。好像很难写代码!!
【问题讨论】:
标签: json angularjs checkbox filter