我无法检索angularjs中所选复选框的值

时间:2016-04-29 10:13:24

标签: angularjs checkbox

任何人都可以告诉我如何在angularjs中检索所选复选框的值。我会给你一个简短的场景。我有一个名为'user'的对象,其中我有一个权限列表作为'user'的成员。现在在jsp中我有几个复选框,我想要的是当我选中复选框时,所选复选框的值应映射到“用户”中存在的权限列表,我该怎么做。 我将显示我的权限复选框jsp代码,如下所示

<div class="form-group required">
<label for="Permissions" class="col-sm-3 control-label">Permissions</label>
<div class="col-sm-6 Nopadding" data-ng-model="ctrl.user.permissionVoList.permissionId">
    <div class="checkbox"   data-ng-repeat="permissionVo in ctrl.permissionVoList" >
        <label data-toggle="tooltip" data-placement="right"
            data-html="true"
            title="<p align='left'>{{permissionVo.description}}</p>">
            <input type="checkbox" value={{permissionVo.permissionId}} /> {{permissionVo.permissionName}}
        </label>
    </div>

</div>

和控制器中的'user'对象如下

 self.user={
                  userId:'1',
                  firstName:'Vishal',
                  middleName:'Vasant',
                  lastName:'Raut',
                  phoneNumber:'9898989898',
                  emailId:'vishal@gmail.com',
                  username:'vishal',
                  password:'111111',
                  notification:'no',
                  costPerHour:'1000',
                  roleVo:{roleId:''},
                  shiftVo:{shiftId:''},
                  permissionVoList:[{permissionId:''}]

            };

2 个答案:

答案 0 :(得分:2)

cat-file
    angular.module('app',[]).controller('ctrlA',function(){
    var self = this;
self.selectedPermissions = [];
     self.user={
                      userId:'1',
                      firstName:'Vishal',
                      middleName:'Vasant',
                      lastName:'Raut',
                      phoneNumber:'9898989898',
                      emailId:'vishal@gmail.com',
                      username:'vishal',
                      password:'111111',
                      notification:'no',
                      costPerHour:'1000',
                      roleVo:{roleId:''},
                      shiftVo:{shiftId:''},
                      permissionVoList :[{permissionId:1,permissionName:"One"},{permissionId:2,permissionName:"Two"}]

                };
self.pushPermission = function(p){

  self.selectedPermissions.push(p);
}

    });

答案 1 :(得分:0)

您可以使用pro-checklist模型检索复选框的数据。访问链接here