我想知道用户选择了哪个复选框,我有这个表,但它不起作用。还有其他选择吗?
<table class="table table-bordered table-hover" style="max-height: 500px; overflow-y: auto" border="1">
<tr>
<th> Nom Exigence</th>
<th> Verifier</th>
</tr>
<tr data-ng-repeat="item in list" style="background-color: #F5F5F5">
<td>
{{item.Nom}}
</td>
<td>
<input type="checkbox" checklist-model="user.list" />
</td>
</tr>
</table>
核实
关闭
当我尝试记录 $scoepe.user.list 时,它向我显示 [] 这是模态 Controller
app.controller('ModalInstanceExigencesCtrl', function ($scope, $modalInstance, list) {
$scope.list = [];
$scope.user = [];
for (var i = 0; i < list.length; i++) {
$scope.list.push(list[i]);
}
console.log($scope.list);
$scope.ok = function () {
$modalInstance.close();
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
$scope.verify = function () {
console.log($scope.user);
};
});
最佳答案
这个 fiddle 应该可以为你完成这项工作:jsfiddle example using checkboxes
Html 代码(与您的代码非常相似):
<div ng-controller="MainCtrl">
<ul>
<li ng-repeat="item in items">
<label class="checkbox">
<input type="checkbox" ng-model="items[$index].checked" />
{{item.name}}
</label>
</li>
</ul>
<hr class="space clearfix" />
{{items | json}}
JS 代码:
var app = angular.module('angularjs-starter', []);
function MainCtrl( $scope )
{
$scope.items = [
{ name:'foo', checked: true },
{ name:'bar' },
{ name:'baz' }
];
}
我只定义了一个名为 items
的 $scope 对象。在我的示例中,每个项目都有一个名称和一个可选值 checked
,该值确定是否选中复选框。
Html 非常先进,我们重复所有 items
,然后绑定(bind)我们的复选框模型 ng-model="items[$index].checked"
。 $index
为我们提供迭代次数,例如我们的第一次迭代绑定(bind)到 ng-model="items[0].checked"
希望有帮助。
关于javascript - 获取在 AngularJS 复选框列表中选中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30049510/