문제

I'm working in a web application. I have a user list that i get from a database and use ng-repeat to list each entry by name like this:

JS:

   $http.get("cretecampaign.php?action=getExecutives").success(function(data) {
        $scope.executives = data;

PHP:

   <form name="myForm">
     <li ng-repeat="executive in executives" class="no-dots">
         <input type="checkbox" name="usertoadd" ng-model="executive.addto" >
         {{ executive.user }}
     </li>
   </form>

I need to pass the user id of the selected users on the list to myForm, but i can't figure out how to do this. I've pass the last few hours searching for an example code but can't find anything like this.

도움이 되었습니까?

해결책

You can look at the $scope.executives array in your controller to find out which users are selected. If a user is selected, they will have a addto property.

So your code might look something like this:

$scope.submit = function(){
  var selected = [];
  angular.forEach($scope.executives, function(executive){
    if(executive.addto){
      selected.push(executive.user.id);
    }
  });
  //Do something with selected...
} 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top