获取所选复选框AngularJS的位置

时间:2016-09-06 12:49:06

标签: angularjs

我想检索已检查值的位置:

HTML:

   <div ng-repeat="i in range(Data.nop)">
                <div class="form-group">

                    <div class="col-md-6 col-xs-12">

                   Option {{i}})

<br>
            <input type="checkbox" ng-model="score1[i-1]" ng-value="{{i-1}}"  name="score1"/>
                <br>
{{score1}}
            <textarea  ng-model="options[i-1]" class="form-control"></textarea>


                    </div>
                    </div>
                </div>

控制器:

$scope.score1=[];

1 个答案:

答案 0 :(得分:0)

以下解决了我最初的问题:

HTML

<div ng-repeat="i in range(Data.nop)">
    <div class="form-group">

        <div class="col-md-6 col-xs-12">
            Option {{i}})
            <br>
            <input type="checkbox" ng-model="score1[i-1]"  name="score1" ng-value="{{i-1}}" ng-true-value="'checked'" ng-false-value="'unchecked'"/>
            <br>
            <textarea  ng-model="options[i-1]" class="form-control" ></textarea>
        </div>
    </div>
</div>

控制器

    $scope.options=[];
    $scope.score1=[];
    $scope.scores=[];

    angular.forEach($scope.score1,function(value,key){
        if (value ==='checked'){
            $scope.scores.push(key);
        }
    });