2015-08-26 48 views
0
$scope.toggleSelection = function($index) { 
    var idx = $scope.employees[$index].id; 

    var result = $.grep($scope.selection, function(e){ return e.id == idx; }); 
    var flg=true; 
    var x=0; 
    for (var i=0; i<$scope.selection.length; i++) { 
     if ($scope.selection[i].id == idx){ 
      flg = false;x=i; 
      break; 
      } 

     } 
     if(flg){ 
     $scope.selection.insert($scope.selection.length,$scope.employees[$index]); 

     }else{ 
     $scope.selection.remove(x); 
     } 

    }; 

回答

1

不使用$indexng-repeat因爲你將有錯誤時,你會嘗試從陣列中刪除項目的員工的所有ID。使用員工ID,ng-repeat="employee in employees track by employee.id

並請給你一些關於你想達到什麼的更多信息。