如何通过点击按钮在重复列表中获取已选中复选框 ID 并将项目添加到变量/数组供以后使用?
HTML:
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if (self) {
NSLog(@"constraints = %@",self.constraints);
}
return self;
}
脚本:
<input id="btnCheck" type="button" value="Next" ng-click="addSelected()" />
<div ng-controller="movieController">
<ul>
<li ng-repeat="movie in Movies">
<input id="chkBox-{{ movie.MovieID }}"
type="checkbox"
ng-checked="selection.indexOf(movie.MovieID) > -1"
ng-click="toggleSelection(movie.MovieID)"
/>
</li>
</ul>
</div>
答案 0 :(得分:0)
您可以使用ng-options进行多项选择。更有用;
<select name="movies" ng-model="selectedMovieIDs"
ng-options="m.MovieID as m.MovieID for m in movies">
</select>
更多信息:ngOptions
答案 1 :(得分:0)
您可以创建一个自定义过滤器,它会返回一个选定的值id,因为您需要传递两个参数来过滤第一个参数将执行检查,如果是,则第二个参数属性数组将从过滤器返回。
<强>标记强>
<body ng-app="app">
<div ng-controller="movieController">
{{(Movies | returnPropertyWhenCheckedTrue: 'checked' :'MovieID')}}
<ul>
<li ng-repeat="m in Movies">
<input id="chkBox-{{ m.MovieID }}" type="checkbox" ng-model="m.checked"/>
</li>
</ul>
</div>
</body>
过滤强>
app.filter('returnPropertyWhenCheckedTrue', function() {
return function(array, propertyToChecked, property) {
var returnArray = [];
angular.forEach(array, function(value, index) {
if (value[propertyToChecked])
returnArray.push(value[property]);
});
return returnArray;
}
});