ngModel似乎存在问题。
我试图获取所选的复选框ID,但它没有保存,因为ngModel没有更改其已检查的属性。
这些只是部分代码段。当我将其中一个检查值转换为true时,ID保存在checkbox数组中(addCustom函数在单击按钮时运行)。
如何解决这个问题,以便我可以获得所选的复选框?
$('.rating').on('click', function(){
$(this) // Our starting point, we're going left/right of this one
.addClass('starred') // Of course, activate the one selected
.nextAll() // Select the "unstarred"
.removeClass('starred') // Deactivate greater ratings not selected
.end() // This cancels the .nextAll() sub-selector, back to this
.prevAll() // Get the lower stars
.addClass('starred') // Activate them
;
});

$scope.checkboxData = [{
name: "Computer Crash",
id: 1,
checked: false
}, {
name: "Computer Restart",
id: 2,
checked: false
}];
$scope.addCustom = function() {
$scope.custom = !$scope.custom; // close modal
// get checkbox id
$scope.checkboxArray = [];
$scope.checkboxData.forEach(function(checkbox) {
if (checkbox.checked) {
console.log(checkbox.id);
$scope.checkboxArray.push(checkbox.id);
}
})
console.log($scope.checkboxArray);
//////
$scope.data.push({
name: $scope.name,
symptom: $scope.checkboxArray,
answer: $scope.answer
});
localStorage.setItem('data', JSON.stringify($scope.data));
};