【发布时间】:2015-07-14 07:49:06
【问题描述】:
我正在尝试使用带有搜索框的复选框创建一个列表。
HTML
<div ng-controller="MainCtrl">
<input type="text" placeholder="Search" ng-model="query">
<div ng-repeat="item in items | filter:query">
<input type="checkbox" id="{{item.id}}" value="{{item.id}}">{{item.name}}
</div>
</div>
JS
myApp.controller('MainCtrl', function ($scope) {
$scope.items = [
{
"id": 1,
"name": "Green",
},
{
"id": 2,
"name": "Yellow",
},
{
"id": 3,
"name": "Blue",
},
{
"id": 4,
"name": "Red",
}
];
});
问题是当我通过搜索框搜索时,复选框状态未保存。例如,当我选中“绿色”时,我在文本框中输入其他内容,然后删除此文本,不再选中选中的“绿色”。我如何才能对复选框状态进行“记忆”?
这里是 plunker 的链接:http://plnkr.co/edit/KHq3AA4guGKA4AqxQrF8
【问题讨论】:
标签: angularjs checkbox ng-repeat angularjs-filter