代码之家  ›  专栏  ›  技术社区  ›  christoph.mue

带对象数组的离子检查表-如何确定是否选中了复选框

  •  0
  • christoph.mue  · 技术社区  · 7 年前

    我的代码应用程序。js:

    jt.controller('TheorieCtrl', function($scope, $window, $ionicPlatform) {
    // .log($window.localStorage);
    // Ready functions
    if ($window.localStorage.getItem('themen') === null) {
        $scope.themen = [{
            name: "Setting1",
            checked: false
        }, {
            name: "Setting2",
            checked: false
        }
        ];
    } else {
        $scope.themen = JSON.parse($window.localStorage['themen']);
    };
    
    $scope.updateThemaLocalStorage = function(items) {
        $window.localStorage['themen'] = JSON.stringify(items);
    };
    

    });

    我的html代码:

     <ion-list>
        <ion-checkbox ng-repeat="thema in themen track by $index" class="checkbox-positive item-checkbox-right" type="checkbox" id="{{thema.id}}" ng-model="thema.checked" ng-change="updateThemaLocalStorage(themen)">
            {{ thema.name }}            
        </ion-checkbox>
    </ion-list>
    

    在另一个控制器中,我想确定是否检查了设置1。 是这样的吗 if($scope.thema.Setting1.checked){“做点什么”} 但这不起作用。我只是需要语法方面的帮助。

    我想这绝对是个新手问题。很抱歉,我确实做了很多搜索和尝试。

    1 回复  |  直到 7 年前
        1
  •  0
  •   alphapilgrim    7 年前

    我认为你应该改变查找方式。如果阵列从未更改。

    if($scope.thema.Setting1.checked){ "do something" } 
    

    预期:

    if($scope.thema[0].name.checked){ "do something" }