AngularJS ng-click在ng-repeat内的两个tds上改变颜色

时间:2016-06-24 16:42:42

标签: angularjs twitter-bootstrap

我有一些代码从数据库中列出表中的项目。单击功能可在绿色和红色之间切换单元格。

<tr ng-repeat="team in Pool">
     <td ng-class="{'btn-danger': namestarted[$index], 'btn-success': !namestarted[$index]}" ng-click="changeColor(team.chrTeamName, $index)">{{ team.chrTeamName }}</td>
     <td>{{ team.intSeed }}</td>
     <td ng-class="{'btn-danger': divstarted[$index], 'btn-success': !divstarted[$index]}" ng-click="changeColor(team.chrDivision, $index)">{{ team.chrDivision }}</td>
</tr> 

控制器:

$scope.namestarted = [];
$scope.divstarted = [];
$scope.changeColor= function (status, index) {
  if(status == "Name"){
     //How to know if the 'Name" is Selected or NotSelected???
     $scope.namestarted [index] = !$scope.namestarted [index];}
  else
     $scope.divstarted [index] = !$scope.divstarted [index];
}

现在当我点击“名称”或“分区”时,我需要知道它是选中还是未选中(是否有效)?

0 个答案:

没有答案