Javascript AngularJ使用一个对象作为另一个对象的过滤器
我试图通过一组来自不同对象的复选框过滤我的ng repeat。对象1保存我的类别,对象2保存我的所有文章 类别对象将变成复选框。这些复选框应充当文章的过滤器。一篇文章可以有多个类别 $scope.类别:Javascript AngularJ使用一个对象作为另一个对象的过滤器,javascript,angularjs,checkbox,Javascript,Angularjs,Checkbox,我试图通过一组来自不同对象的复选框过滤我的ng repeat。对象1保存我的类别,对象2保存我的所有文章 类别对象将变成复选框。这些复选框应充当文章的过滤器。一篇文章可以有多个类别 $scope.类别: [ { "id": "1", "title": "Blog" }, { "id": "2", "title": "News" } ] [ { "id": "1", "title": "Whats going on",
[
{
"id": "1",
"title": "Blog"
},
{
"id": "2",
"title": "News"
}
]
[
{
"id": "1",
"title": "Whats going on",
"categories":{
"results" : [1,2,3]
}
},
{
"id": "2",
"title": "Trump!",
"categories":{
"results" : [3]
}
}
]
<div class="filter-pills" ng-repeat="cat in categories">
<input type="checkbox" ng-model="filter[cat.Id]" ng-checked="cat.checked"/>{{cat.Title}}
</div>
<div class="col-lg-3 col-md-4" ng-repeat="item in articlesFinal"></div>
$scope.文章:
[
{
"id": "1",
"title": "Blog"
},
{
"id": "2",
"title": "News"
}
]
[
{
"id": "1",
"title": "Whats going on",
"categories":{
"results" : [1,2,3]
}
},
{
"id": "2",
"title": "Trump!",
"categories":{
"results" : [3]
}
}
]
<div class="filter-pills" ng-repeat="cat in categories">
<input type="checkbox" ng-model="filter[cat.Id]" ng-checked="cat.checked"/>{{cat.Title}}
</div>
<div class="col-lg-3 col-md-4" ng-repeat="item in articlesFinal"></div>
复选框:
[
{
"id": "1",
"title": "Blog"
},
{
"id": "2",
"title": "News"
}
]
[
{
"id": "1",
"title": "Whats going on",
"categories":{
"results" : [1,2,3]
}
},
{
"id": "2",
"title": "Trump!",
"categories":{
"results" : [3]
}
}
]
<div class="filter-pills" ng-repeat="cat in categories">
<input type="checkbox" ng-model="filter[cat.Id]" ng-checked="cat.checked"/>{{cat.Title}}
</div>
<div class="col-lg-3 col-md-4" ng-repeat="item in articlesFinal"></div>
{{cat.Title}}
ng重复:
[
{
"id": "1",
"title": "Blog"
},
{
"id": "2",
"title": "News"
}
]
[
{
"id": "1",
"title": "Whats going on",
"categories":{
"results" : [1,2,3]
}
},
{
"id": "2",
"title": "Trump!",
"categories":{
"results" : [3]
}
}
]
<div class="filter-pills" ng-repeat="cat in categories">
<input type="checkbox" ng-model="filter[cat.Id]" ng-checked="cat.checked"/>{{cat.Title}}
</div>
<div class="col-lg-3 col-md-4" ng-repeat="item in articlesFinal"></div>
当我更新我的filter
数组并将其与ng repeat
中使用的对象进行比较时,我尝试了不同的解决方案,如ng change
我似乎无法理解这一点。有什么建议吗?试试这个
<div class="filter-pills" ng-repeat="cat in categories">
<input type="checkbox" ng-model="cat.checked"/>{{cat.title}}
</div>
<div class="col-lg-3 col-md-4" ng-repeat="item in articles | filter: catFilter">{{item.title}}</div>
很好!谢谢