Refresh ng-repeat data

后端 未结 4 1625
梦毁少年i
梦毁少年i 2021-01-19 17:30

I have a big list containing all of my data, and I have another shorter list containing only the selected data. Originally, all the data is selected so both lists are identi

4条回答
  •  死守一世寂寞
    2021-01-19 18:09

    Please check with this code and let me know whether it solves your issue. Also please check this working plnkr of your example scenario.

    Template:

        

    Controller:

    $scope.update_selected_Brain_regions = function (region) {
        for (var i = 0; i < $scope.brain_regions.length; i++) {
            var current_region = $scope.brain_regions[i];
            if (current_region.id === region.id) {
                if (region.show) {
                    $scope.selected_brain_regions.push(current_region);
                } else {
                    var index = $scope.selected_brain_regions.map(function(x){ return x.id; }).indexOf(current_region.id);
                    $scope.selected_brain_regions.splice(index,1);
                }
            }
        }
    };
    

提交回复
热议问题