Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 切换状态后如何在角度中保留复选框值?_Javascript_Angularjs_Checkbox_Ionic - Fatal编程技术网

Javascript 切换状态后如何在角度中保留复选框值?

Javascript 切换状态后如何在角度中保留复选框值?,javascript,angularjs,checkbox,ionic,Javascript,Angularjs,Checkbox,Ionic,我有一个由JSON结构创建的表,该表有一个带有复选框的过滤器,根据该过滤器,我们可以选择在表中一次要查看的所有字段,我们可以在一次查看5个可见列。 当我选择5个不同的复选框来重新创建一个表时,我面临的问题是,在切换状态后,选中的值不会被保留。 我希望在重新访问该页面时保留上次选中的值 这是控制器内的函数,在选择默认的前5个复选框后创建完整表: function tablePopulate() { $scope.filteredLabel = [];

我有一个由JSON结构创建的表,该表有一个带有复选框的过滤器,根据该过滤器,我们可以选择在表中一次要查看的所有字段,我们可以在一次查看5个可见列。 当我选择5个不同的复选框来重新创建一个表时,我面临的问题是,在切换状态后,选中的值不会被保留。 我希望在重新访问该页面时保留上次选中的值

这是控制器内的函数,在选择默认的前5个复选框后创建完整表:

function tablePopulate() {
            $scope.filteredLabel = [];
            $scope.unfilteredLabel = [];
            $scope.filteredData = [];
            console.log($scope.unfilteredLabel.length);
            label = FullTableRecord.getLabel(); //Get the full labels  in label[] array
            console.log("anki" + label);
            for (i = 0; i < label.length; i++) {
                var j = 0
                if (i < 5) {
                    $scope.unfilteredLabel.push({
                        label: label[i],
                        value: true,

                    });

                } else {
                    $scope.unfilteredLabel.push({
                        label: label[i],
                        value: false,
                    });
                }

            }
            $scope.filterRemCount=5;
            $scope.clicked = true;
            console.log("unfilterd label at 668");
            console.log($scope.unfilteredLabel.length);
            /*selectField() function called to check which field has been selecteds  */
            localData = TableData.get(); //Get the Complete set of data from TableData service
            $scope.cLoader = false;
            rePaintTable();

        }
此函数用于检查选中的复选框:

 $scope.selectField = function() {
            console.log("select field function called");
            count = 0;
            for (i = 0; i < $scope.unfilteredLabel.length; i++) {
                //console.log($scope.unfilteredLabel[i].value);
                if ($scope.unfilteredLabel[i].value) {
                    count++; //count variable contains the number of fields selected
                }
            }
            $scope.filterRemCount=count;
            console.log("Count value is:" + count);
            if (count > 4) {
                console.log("inside count >5")
                $scope.clicked = true;

            } else {
                console.log("inside count <5")
                $scope.clicked = false;
            }
            // console.log("$scope.clicked" + $scope.clicked);
            // console.log("$scope." + $scope.clicked);
        }
此函数将根据用户从过滤器中选择的字段集从完整的数据集中获取数据

function rePaintTable() {
        $scope.isFilterOpen = false;
        $scope.filteredData = [];
        $scope.filteredLabel = [];
        var tempFilterLabel= [];
        //console.log("inside rePaintTable function");

        for (i = 0; i < $scope.unfilteredLabel.length; i++) {
            if ($scope.unfilteredLabel[i].value) {

                console.log($scope.unfilteredLabel[i].label);
                tempFilterLabel.push($scope.unfilteredLabel[i].label);
                $scope.filteredLabel = tempFilterLabel;

                // $scope.filteredLabel.push($scope.unfilteredLabel[i].label);
            }
        }
        // console.log("Filtered Label");
        //console.log($scope.filteredLabel);
        console.log("Filtered Data");
        console.log($scope.filteredData);
        for (i = 0; i < localData.length; i++) {
            $scope.filteredData.push([]);
            for (j = 0; j < localData[i].length; j++) {
                if ($scope.unfilteredLabel[j].value) {
                    $scope.filteredData[i].push(localData[i][j]);
                }
            }

        }
         console.log("Filtered Data 2");
        console.log($scope.filteredData); this console prints the array of objects according to the checked values only.


    }

使用angular Services设置并获取所选过滤器扫描您提供了一个示例吗?我已经为相同的u形按钮创建了一个演示使用angular Services设置并获取所选过滤器扫描您提供了一个示例吗?我已经为相同的u形按钮创建了一个演示