gpt4 book ai didi

javascript - 无法刷新 Angularjs 中的 ng-repeat

转载 作者:行者123 更新时间:2023-11-30 14:56:30 25 4
gpt4 key购买 nike

我正在尝试使用一个函数来检查复选框树中的所有复选框。它正在成功选中和取消选中,但是如果我选择一个复选框然后按下全部选中,然后取消选中,单个复选框将保持卡住状态

HTML

<fieldset id="field3">
<table>
<tr ng-repeat="e in empdepts | groupBy:'dep_LDesc'">
<td>
<label ng-click="showContent = !showContent"></label>
<details ng-open="showContent">
<summary>
<input type="checkbox" ng-model="chk" /> {{e[0].dep_LDesc}}</summary>
<div ng-repeat="employee in e">
<input type="checkbox" ng-checked="chk"> {{employee.Sname}}
</div>
</details>
</td>
</tr>
</table>
<hr />
<table>
<tr>
<td>
<input type="checkbox" ng-model="all" ng-click="selectall(all)" /> All Departments</td>
</tr>
<tr>
<td>
<input type="checkbox" ng-model="self" /> Self Services </td>
</tr>
</table>
</fieldset>

Controller

$scope.selectall = function (all) {
if (all) {
$scope.chk = true;
}
else
{
$scope.chk = false;
}
}

LoadEmpDepts();

function LoadEmpDepts() {
Assignments.getempdepts().then(function (response) {
$scope.empdepts = (response.data);
console.log($scope.empdepts);
})
}

enter image description here

最佳答案

您需要为单个元素设置 checked 属性,因此可以选择在数组的每个元素内设置一个 checked 属性。

所以每当复选框被选中时更新属性。并在检查所有元素时使所有元素的检查属性为真。

  <label for="{{all.type}}"  ng-if="x.type === 'ALL'" >{{x.type}}</label>

例子,

DEMO

关于javascript - 无法刷新 Angularjs 中的 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47187782/

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