2016-03-21 8 views
0

Adların yanında bir onay kutusu tablosu gösteren kalıcı bir iletişim kutusu var. Bu ismin değerini seçmek için bu onay kutularını atamak istiyorum (yani, masadaki "Jon" un yanındaki kutuyu işaretlediğimde, bu ismin seçilmesini istiyorum). Birden çok onay kutusunu tıklattığımda, bunu javascript'e bir dizi olarak iletmek istiyorum.Çoklu onay kutularının seçilmesi ve diziye değerlerin atanması - HTML/Javascript

</div> 
      <div class="modal-body"> 
       <table class="table table-striped table-hover "> 
       <thead> 
        <tr> 
         <th>Select</th> 
         <th>User Name</th>      
        </tr> 
       </thead> 
       <tbody> 
        <tr ng-repeat="user in users" ng-hide="user.name === lic.users.name"> 
         <td><input type="checkbox" ng-model="user.selected" id="userId"/></td> 
         <td>{{user.name}}</td> 
        </tr> 
       </tbody> 
       </table> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button> 
       <button type="button" class="btn btn-primary btn-sm" ng-click="addLicUser(userId, lic.license.id)">Ok</button> 
      </div> 
     </div> 


<div class="modal" id="add-new-lic-user"> 
    <div class="modal-dialog"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <h4 class="modal-title">Add License User</h4> 
     </div> 
      <div class="modal-body"> 
       <p>Are you sure you want to add these users to this license?</p> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button> 
       <button type="button" class="btn btn-primary btn-sm" ng-click="processLicenseUser">Ok</button> 
      </div> 
     </div> 
    </div> 

:

Esasen: - iletişim üzerine 'Tamam'> Basın - -> İsimler seçilen> JS koduna dizide

HTML kodunu isimlerin id göndermek adının yanında onay kutularını tıklayın

JavaScript:

$scope.addLicenseUser = function(){ 
    $("#add-lic-user").modal('show'); 
}; 

    $scope.addLicUser = function (usId, licId){ 
    $scope.licenseId = licId; 
    $scope.userIdToAdd = usId; 
    $("#add-lic-user").modal('hide'); 
    $("#add-new-lic-user").modal('show'); 
    }; 

    $("#processLicenseUser").click(function(e){ 
    e.preventDefault(); 
    $scope.processLicenseUser(); 

}); 

$scope.processLicenseUser = function() { 

    usId.forEach(function(entry){ 
    // 
    var req = { 
      method: 'POST', 
      url: '/rest/v1/porta/mapping', 
      headers:{ 
       'Content-Type': 'application/json', 
       'GoverlanHeader_1': 'Yes', 
       'x-access-token': $scope.authInfo.token 
      }, 
      data: {'userId': $scope.userIdToAdd, 'licenseId': $scope.licenseId} 
     }; 

cevap

0

zaten her u seçilen özelliğine bağlamak ser, sen basit bir filtre yapabilirsiniz

$scope.processLicenseUser = function() { 
    var selected_users = []; 
    $scope.users.forEach(function(user) { 
    if user.selected { 
     selected_users.push({'userId': user.Id, 'licenseId': user.licenseId}); 
    } 
    }) 

    var req = { 
     method: 'POST', 
     url: '/rest/v1/porta/mapping', 
     headers:{ 
      'Content-Type': 'application/json', 
      'GoverlanHeader_1': 'Yes', 
      'x-access-token': $scope.authInfo.token 
     }, 
     data: selected_users 
    }; 
0

o "Ben javascript için bir dizi olarak bu geçmek istiyorum."

Kodunuzda, tıklatılan öğeyi bir diziye itmiyorsunuz.

$scope.users = []; 

    $scope.checked = function() { 
    $scope.user.splice(0, $scope.user.length); 
    $scope.user.push('id'); 
    }; 
});