带有ngRepeat的角度选择框

时间:2017-03-01 16:46:03

标签: javascript angularjs json select angularjs-ng-repeat

我选择了ngRepeat内的下拉列表和复选框,这些复选框由本地存储的JSON对象数组填充。我通过弹出模式更改数组的内容,并可以验证数组是否正确更新。

我的问题是,在我手动刷新页面之前,选择框不会更新基于数组的下拉选项。确定复选框状态的数据也在数组中并立即更新。

以某种方式添加$window.location.reload()会阻止更新数组,$scope.$apply()会引发错误[$rootScope:inprog]

感谢任何帮助。

<tr ng-repeat="x in allTypes | orderBy:'name'">
    <td><a style="cursor: help" title="{{x.desc}}"> {{x.name}} </a></td>                    
    <td><select class="form-control" ng-model="listA" ng-init="listA = dropDown('ACTIVE', x.name, [])" ng-change="listDrop(x.name, 'ACTIVE', listA)" ng-options="w.value as w.id.key for w in allLevels | orderBy:'value'">
        <option value=""> Select Active </option>
    </select></td>  
    <td><select class="form-control" ng-model="listI" ng-init="listI = dropDown('INACTIVE', x.derogName, [])" ng-change="listDrop(x.derogName, 'INACTIVE', listI)" ng-options="w.value as w.id.key for w in allLevels | orderBy:'value' ">
        <option value=""> Select Inactive </option>
    </select></td>      
</tr>

下面是更改数组内部内容的代码

$scope.existingConfig = function(data){
    dataList = $localStorage.newList[0];
    $http.get(service + 'dataConfig/' + data.id).
        then(function(response) {
            $scope.listE = response.data;
            for(i=0; i<$scope.listE.length; i++){
                var add = true;
                for(x=0; x<dataList.length; x++){
                    if($scope.listE[i].name == dataList[x].name){
                        add = false;
                        if($scope.listE[i].status == 'ACTIVE'){
                            $scope.listA = $scope.listE[i].level;
                            dataList[x].active.level = $scope.listE[i].level;
                            dataList[x].active.type = $scope.listE[i].type;
                        }
                        else{
                            $scope.listI = $scope.listE[i].level;
                            dataList[x].inactive.level = $scope.listE[i].level;
                            dataList[x].inactive.type = $scope.listE[i].type;
                        }
                    }
                }
                if(add == true){
                    myObj = {};
                    myObj.name = $scope.listE[i].name;
                    if($scope.listE[i].status == 'ACTIVE'){
                        myObj.active = {};
                        myObj.inactive = {};
                        myObj.active.level = $scope.listE[i].level;
                        myObj.active.type = $scope.listE[i].type;
                        dataList.push(myObj);
                        $scope.listA = $scope.listE[i].level;
                    }
                    else{
                        myObj.active = {};
                        myObj.inactive = {};
                        myObj.inactive.level = $scope.listE[i].level;
                        myObj.inactive.type = $scope.listE[i].type;
                        dataList.push(myObj);
                        $scope.listI = $scope.listE[i].level;
                    }           
                }
            }               
        });
}

0 个答案:

没有答案