gpt4 book ai didi

javascript - ng-repeat 与动态数组 : view not updated

转载 作者:行者123 更新时间:2023-12-03 09:42:03 35 4
gpt4 key购买 nike

我在 block 内有一些复选框,如下所示:

<div ng-show="searchIn.IS" class="filterContent">
<div ng-click="toggleFilter('IS')">
<span class="{{filters.IS}}FilterIcon"></span>
Information System :
</div>
<div ng-show="filters.IS">
<md-checkbox ng-repeat="IS in ISList" ng-click="setISSearch(IS)" ng-checked="isInISSearch(IS)">
{IS}}
</md-checkbox>
</div>
</div>
<br />
<div ng-show="searchIn.area" class="filterContent">
<div ng-click="toggleFilter('area')">
<span class="{{filters.area}}FilterIcon"></span>
Area :
</div>
<div ng-show="filters.area">
<md-checkbox ng-repeat="area in filterAreaList" ng-click="setAreaSearch(area)" ng-checked="isInAreaSearch(area)" ng-show="isInCurrentAreas(area)">
{{area}}
</md-checkbox>
</div>
</div>

所以问题是,每次我选中或取消选中 ISList block 中的复选框时,filterAreaList 都会更改。但 View 没有更新,所有区域仍然显示。我还尝试了 ng-if 而不是 ng-show

$scope.filterAreaList = [];

$scope.getAreaFilters = function () {
$scope.searchedIS = $scope.ISList.slice();
for (var i = $scope.searchedIS.length; i >= 0; i--) {
if ($scope.searched.IS.indexOf($scope.searchedIS[i]) === -1)
$scope.searchedIS.splice(i, 1);
}
for (var i = 0; i < $scope.areaList.length; i++) {
for (var j = 0; j < $scope.searchedIS.length; j++)
if ($scope.hasArea($scope.searchedIS[j], $scope.areaList[i]))
$scope.filterAreaList.push($scope.areaList[i]);
}
};

$scope.isInCurrentAreas = function (area) {
if ($scope.filterAreaList.indexOf(area) === -1)
return false;
return true;
};

其他一些主题指出了这一点:http://www.bennadel.com/blog/2443-rendering-dom-elements-with-ngrepeat-in-angularjs.htm

但我真的不知道如何将其应用到我的案例中。

最佳答案

好吧,我实际上错过了一些事情:

为了使其正常工作,我在 getAreaFilters() 函数中添加了: $scope.filterAreaList = []; ,然后调用 getAreaFilters( ) 在我的 setAreaSearch(area)

就是这样。

关于javascript - ng-repeat 与动态数组 : view not updated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31158320/

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