Javascript 获取选中的复选框列表AngularJS
我想知道用户选择了哪个复选框,我有这个表,但它不起作用。还有别的选择吗Javascript 获取选中的复选框列表AngularJS,javascript,angularjs,asp-classic,Javascript,Angularjs,Asp Classic,我想知道用户选择了哪个复选框,我有这个表,但它不起作用。还有别的选择吗 <table class="table table-bordered table-hover" style="max-height: 500px; overflow-y: auto" border="1"> <tr> <th> Nom Exigence</th> <th> Verifier</th> &l
<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>
名义紧急情况
验证者
{{item.Nom}
验证
接近
当我尝试记录$scoepe.user.list时,它会显示[]
这是模态控制器
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);
};
app.controller('ModalInstanceExigencesCtrl',函数($scope,$modalInstance,list){
$scope.list=[];
$scope.user=[];
对于(变量i=0;i
})) 这把小提琴应该能帮你: Html代码(与您的代码非常相似): 我只定义了一个名为
items
的$scope对象。在我的示例中,每个项目都有一个名称和一个可选值checked
,该值决定是否选中复选框
Html非常先进,我们重复所有项目
,然后绑定我们的复选框modelng model=“items[$index]。选中“
$index
提供了迭代次数,例如,我们的第一次迭代绑定到ng model=“items[0]。选中”
希望对您有所帮助。您也可以使用这种方式进行尝试 Html代码:
$scope.collectNumber=函数(联系人,索引){
如果(已检查联系人){
}
否则{
}
}
{{contact.Name}
我的例子中的$scope.item是动态的,我不知道它包含多少个对象。我的例子中只有3个项目。您可以动态添加任意数量的内容。我想我没有完全理解这个问题。动态项目数的问题在哪里?编辑:我没有看到你使用清单模型,这是我的错。根据官方文件,我认为你忘记了checklist value=“item”
我的第一个解决方案应该有效,而不使用检查表模型。
<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}}
var app = angular.module('angularjs-starter', []);
function MainCtrl( $scope )
{
$scope.items = [
{ name:'foo', checked: true },
{ name:'bar' },
{ name:'baz' }
];
}