【发布时间】:2016-11-21 01:11:56
【问题描述】:
我有产品列表,每个产品都有学生列表。 我有要显示的产品 JSON;在该产品 JSON 中,我为学生提供了另一个 JSON:
[{"CustId":7191,"CFirstName":"Kynan"},{"CustId":29689,"CFirstName":"Pete"},{"CustId":29690,"CFirstName":"Gina"},{"CustId":29692,"CFirstName":"Jo"}]
我想为每个学生和每个产品添加复选框。
这是我为每个产品所做的:
<span ng-repeat="customer in productVM.product.Customers">
<label class="checkbox-inline" style='margin-left:0px !important; margin-right: 10px !important; '>
<input class="options" ng-model="customer.CustId" type='checkbox' name="selectedStudent[]"
value="{{customer.CustId}}" ng-checked="selection.indexOf(customer.CFirstName) > -1" ng-click="toggleSelection(customer.CFirstName)">
{{customer.CFirstName}}
</label>
</span>
角度代码:
$scope.selection = [];
$scope.toggleSelection = function toggleSelection(customerName) {
var idx = $scope.selection.indexOf(customerName);
// is currently selected
if (idx > -1) {
$scope.selection.splice(idx, 1);
}
// is newly selected
else {
$scope.selection.push(customerName);
}
};
我有两个问题: 1. 每当我点击产品的任何复选框时;选中所有产品的类似复选框(未选中时类似)。 2. 如何获取选中复选框的值。
【问题讨论】: