【发布时间】:2019-03-12 00:51:09
【问题描述】:
我有一个要使用单选按钮过滤的项目列表,这是我的数组的一个示例:
$scope.items = [
{
"name":"person 1",
"section":"one",
"job":false
},
{
"name":"person 2",
"section":"two",
"job":true
},
{
"name":"person 3",
"section":"one",
"job":false
},
{
"name":"person 4",
"section":"one",
"job":true
}
];
在我的 HTML 中,我有一个 ng-repeat 列表,我想用 单选按钮 对其进行过滤:
<div class="menu">
<label>
<input type="radio" ng-model="filteradio.section" value="">
<p>All</p>
</label>
<label>
<input type="radio" ng-model="filteradio.section" value="one">
<p>Section 1</p>
</label>
<label>
<input type="radio" ng-model="filteradio.section" value="two">
<p>Section 2</p>
</label>
<label>
<input type="radio" ng-model="filteradio.job" value="true">
<p>People with job</p>
</label>
</div>
<table>
<tr>
<td>Name</td>
<td>Section</td>
<td>Job</td>
</tr>
<tr ng-repeat="item in items | filter:filteradio:strict">
<td>{{item.name}}</td>
<td>{{item.section}}</td>
<td ng-if="item.job">yes</td>
</tr>
</table>
问题是 最后一个单选按钮 不起作用,因为当我选择带有 "filteradio.section" 的按钮时,它们可以正常工作,但是一旦我点击在 "filteradio.job" 中,其他单选按钮保持选中状态!
我尝试将相同的“name 属性”添加到所有单选按钮,但是一旦我单击 "filteradio.job",所有项目都会消失。
如何按“部分”以及“是否有工作”过滤它们?有没有更简单的方法来解决这个问题?
【问题讨论】:
标签: angularjs filter radio-button