gpt4 book ai didi

html - Angular : How to uncheck all checkboxes with a link?

转载 作者:搜寻专家 更新时间:2023-10-31 21:57:47 24 4
gpt4 key购买 nike

这是我的 fiddle :http://jsfiddle.net/VSph2/280/

我正在尝试取消选中 checkbox 并使用链接重置范围变量的值,但是,它似乎不起作用。有人可以帮忙吗?

Javascript:

var app = angular.module('myApp', []);

app.controller('IndexCtrl', ['$scope', function($scope) {

$scope.colors = [
{id: 1, name: "Blue"},
{id: 2, name: "Green"},
{id: 3, name: "Red"}
];
$scope.color_ids = [];

$scope.clearAll = function() {
angular.forEach($scope.color_ids, function(color_id) {
color_id.checked = false; //nothing works!!
color_id.selected = false; //
});
$scope.color_ids = [];
$scope.color_ids.selected = false; //doesn't work either
};

}]);

HTML:

<div ng-controller="IndexCtrl">{{1+1}}
<h2>Products</h2>
<div class="filters col-two">
<a ng-click="clearAll()">Clear all filters</a>
<h3>Color</h3>
<div ng-repeat="color in colors">
{{ color.name }} <input type="checkbox" ng-model="color_ids">
</div>
</div>
</div>

最佳答案

您永远不会向 color_id 数组添加任何内容,因此 foreach 不会迭代任何内容。

我更新了您的代码以仅使用主颜色数组并在其上添加一个 selected 属性:

http://jsfiddle.net/VSph2/283/

html:

{{ color.name }} <input type="checkbox" ng-model="color.selected">

JavaScript:

angular.forEach($scope.colors, function(color_id) {        
color_id.selected = false;
});

关于html - Angular : How to uncheck all checkboxes with a link?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24944030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com