[英]How to get a checkbox value from response by using Angular js
我试图在数据库中添加一个复选框值,并且它的工作完美。
问题是如果我需要从响应得到结果后将其选中的复选框显示为-1,但是我需要复选框的值为0,1,2等。
如果我单击一个复选框值,则其索引值必须仅更改为-1,但其更改为0或其他某个值
在我的代码下面
HTML:
<div ng-repeat="tag in edit_tag_list">
<input type="checkbox" ng-model="tag.selected" id="{{tag.id}}" value="{{tag.id}}" ng-checked="selectionTagList.indexOf(tag.id) > -1" ng-click="toggleSelection(tag.id)" style="cursor: pointer;" ng-true-value="checked" ng-false-value="">
<input type="checkbox" ng-model="tag.selected" id="{{tag.id}}" value="{{tag.id}}" ng-checked="tag.checked='yes'" ng-click="toggleSelection(tag.id)" style="cursor: pointer;" ng-true-value="checked" ng-false-value="">
JS:
$scope.toggleSelection=function(tageName){
var idx=$scope.selectionTagList.indexOf(tageName);
if(idx > -1)
{
$scope.selectionTagList.splice(idx,1);
}
else
{
$scope.selectionTagList.push(tageName);
}
console.log($scope.selectionTagList);};
我认为您在以下行中有问题:
<input type="checkbox" ng-model="tag.selected" id="{{tag.id}}" value="{{tag.id}}" ng-checked="selectionTagList.indexOf(tag.id) > -1" ng-click="toggleSelection(tag.id)" style="cursor: pointer;" ng-true-value="checked" ng-false-value="">
此时: ng-checked="selectionTagList.indexOf(tag.id) > -1"
此处>
符号充当输入标签的闭合锚点,而不是大于符号。
因此,将>
替换为>
。 这应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.