2016-12-10 6 views
0

内の任意のボックスを選択されていないチェックボックスのHTMLコードはデータベースから動的な値initiazationためではなく、チェックボックスのチェックボックスを使用していますです私のチェックボックスは、ここ* angularjs

   <div class="widget-body" style="display: block;"> 
         <div class="widget-main"> 
           <div class="table-responsive"> 
           <table class="table"> 

           <thead> 
           <tr> 
           <th>item</th> 
           <th>received</th> 
            </tr> 
           </thead> 

        <tbody ng-repeat="emp in nodueaccountassets">  
     <tr> 
<td>{{emp}}</td> <td> <input type="checkbox" ng-model="emp.selected" value="{{emp.name}}"/></td> 

          </tr> 
         </tbody> 
        </table> 
        </div> 
       </div> 
      </div> 

とJS *任意の値を選択されていませんコントローラコードが

 angular.forEach($scope.nodueaccountassets,function(emp){ 
     if (emp.selected) $scope.albumNameArray.push(emp.name); 

      alert(emp.selected); 
+0

angular.forEachはどこで実行されますか?そのコンテキストを投稿してください... – Vi100

答えて

0

は、あなたが選択した従業員を取得したいと仮定している、あなたは、これを行うことができます

あなたのような応答を取得している場合は、おそらくあなたの代わりにブール値の文字列形式でemp.selectedのために、サーバから取得された値は、あなたが「真」のような値、

チェックを取得している

var app = angular.module("app", []); 
 

 
app.controller("listController", ["$scope", 
 
    function($scope) { 
 
    $scope.albumNameArray = []; 
 
    $scope.nodueaccountassets = [{ 
 
     "name": "Raymond", 
 
     "age": 28, 
 
     "selected": false 
 
    }, { 
 
     "name": "Bruce", 
 
     "age": 96, 
 
     "selected": false 
 
    }, { 
 
     "name": "Laura", 
 
     "age": 62, 
 
     "selected": false 
 
    }]; 
 
    $scope.getSelected = function() { 
 
     angular.forEach($scope.nodueaccountassets, function(emp) { 
 
     if (emp.selected) 
 
     $scope.albumNameArray.push(emp.name); 
 
     }) 
 
    } 
 

 
    } 
 

 
]);
<!doctype html> 
 
<html ng-app="app"> 
 

 
<head> 
 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js"></script> 
 
    <script src="script.js"></script> 
 
</head> 
 

 
<body> 
 
    <div ng-controller="listController"> 
 
    <div class="widget-main"> 
 
     <div class="table-responsive"> 
 
     <table class="table"> 
 
      <thead> 
 
      <tr> 
 
       <th>item</th> 
 
       <th>received</th> 
 
      </tr> 
 
      </thead> 
 
      <tbody ng-repeat="emp in nodueaccountassets"> 
 
      <tr> 
 
       <td>{{emp}}</td> 
 
       <td> 
 
       <input type="checkbox" ng-model="emp.selected" value="{{emp.name}}" /> 
 
       </td> 
 

 
      </tr> 
 
      </tbody> 
 
     </table> 
 
     </div> 
 
    </div> 
 

 
    <button ng-click="getSelected()">Get Selected</button> 
 
    <ul> 
 
     <li ng-repeat=" opt in albumNameArray"> 
 
     {{ opt }} 
 
     </li> 
 
    </ul> 
 

 
    </div> 
 
</body> 
 

 
</html>

+0

私のnodueaccountassetsの値がデータベースから来ていて、選択しようとするとチェックボックスが選択されていません –

+0

どうしますか? – Sajeetharan

0

この場合、選択したオブジェクトをブール値に変換する必要があります。

[{ 
name: 'sushil', 
selected: "true" 
}] 
+0

あなたは私の値が次のような文字列形式で来るようにしています:$ scope.nodueaccountassets = data.list;しかし、チェックボックスでバインドしたいのは、htmlで意味をなす方法です。​​{{emp}} ​​<入力タイプ= "チェックボックス" ng-model = "emp.selected" value = "{{emp.name}}" /> –

関連する問題