0

我正在制作一个表格,这个表格有很多复选框,

我想获取复选框值,并将其设置为模型,

该模型将提交服务

这是我的代码

<form name="form" ng-submit="add()">
  <dl>
    <dt>Manager Id</dt>
      <dd ng-repeat="user in User.user" >
        <input name="userName[user.userId][]" type="checkbox" 
          ng- model="newProgram.program.managerId" 
          ng-true-value="{{user.userId}}" ng-false-value="{{user.userId}}" check />
          {{user.userUsername}}
       </dd>
   <dt>Member Id</dt>
     <dd ng-repeat="user in User.user">
       <input name="userName[user.userId][]" type="checkbox" 
         ng-model="newProgram.program.memberId" value= "{{user.userId}}" check />
         {{user.userUsername}}
     </dd>
 </dl>
 <div class="form-actions">
   <button type="submit" 
    ng-disabled="form_edit.$invalid || isUnchanged(newProgram)" >Add</button>
</div>
</form>



angular.module('elnApp')
  .directive('check', function () {
    return {
     restrict: 'A',
     require: 'ngModel',
     link: function(scope, elm, attr, ngModelCtrl, $filter){ 
          elm.bind('click', function() {
            scope.$watch('newProgram.program.managerId', function (value){
               // set {{user.userId}} to ngModel
              }

          });
        });
    }
  }
});




angular.module('elnApp')
 .controller('AddCtrl', function ($scope, programService, userService) {
  $scope.master= {};

  $scope.add = function () {
    programService.add({

  }, $scope.newProgram, function (data) {
    $location.path('/grid');
  });
};

$scope.isUnchanged = function(user) {
  return angular.equals(user, $scope.master);
};

$scope.User= {'user': userService.query()};

 });

我搜索了很多数据,但什么都没有???

请帮忙

多谢 !

4

1 回答 1

0

这是我能想到的最简单的方法。 http://plnkr.co/edit/vVuV59Vwc6wJ8ptBcfmI?p=preview

当某些东西似乎不起作用时,我建议使用浏览器的开发控制台。另外,从最简单的实现开始。

js:

<input type="checkbox" check="model" value="{{ value }}"/>

html:

app.directive('check', function() {
  return {
    scope: { model: '=check', value: '@' },
    link: function( scope, elem ) {
      elem.bind('click', function() {
        var value = elem.attr('checked') ? scope.value : null;
        scope.$apply(function() {
          scope.model = value;
        });
      });
    }
  };
});
于 2013-08-15T08:55:42.480 回答