【发布时间】:2023-03-29 11:25:01
【问题描述】:
我是 AngularJS 的初学者,我有一个问题,这里是我的代码:
$scope.categories = [{
"id": 506,
"name": "test"
}, {
"id": 510,
"name": "aaa"
}, {
"id": 1,
"name": "bbb"
}, {
"id": 2,
"name": "ccc"
}, {
"id": 3,
"name": "eee"
}, {
"id": 4,
"name": "fff"
}];
$scope.contents = [{
"id": 0,
"categoryId": 506,
"title": "test1"
}, {
"id": 1,
"categoryId": 506,
"title": "test2"
}, {
"id": 2,
"categoryId": 506,
"title": "test3"
}, {
"id": 3,
"categoryId": 1,
"title": "test4"
}];
<div>
<label>
<input type="radio" name="category" ng-model="cc" ng-value="" checked/>all
</label>
<label ng-repeat="categoryItem in categories" ng-init="i= $parent">
<input type="radio" name="category" ng-model="i.cc" ng-value="{{categoryItem.id}}" />{{categoryItem.id}}
</label>
</div>
<ul>
<li ng-repeat="content in contents | filter:{categoryId: cc||undefined}">
<h3>id:{{content.categoryId}}</h3>
<p>{{content.title}}</p>
</li>
</ul>
我希望能够通过选择单选来查看所有项目,此外,我希望始终选择其中的第一个。就像现在它不起作用,我真的不知道为什么。
【问题讨论】:
标签: javascript angularjs filter angularjs-scope