2016-06-26 41 views
2

我有一些代碼從數據庫中列出了表中的項目。點擊功能在綠色和紅色之間切換單元格。如何確定該字段是否在AngularJS中被選中

<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]; 
} 

現在,當我點擊「名稱」或「項」,我需要知道它是否被選中NotSelected(活躍)?

+1

通行證'team'到'changeColor()'函數檢查stattus –

+0

什麼是當前特定問題或問題?你已經展示了一些代碼,但沒有給出任何有效或不產生任何錯誤的線索。查看[問] – charlietfl

+0

查理:代碼工程很好,但是當我點擊ChangeColor()時,我需要能夠捕捉它的狀態是否被選中? – Kushi

回答

0

你可以看看下面的pluker鏈接...它會給你一個更好的主意

https://plnkr.co/edit/9GbNn2RTSsdeiKZZjt0T?p=preview

$scope.setSelected = function(idSelectedVote) { 
    $scope.idSelectedVote = idSelectedVote; 
} 

<ul ng-repeat="vote in votes" ng-click="setSelected(vote.id)" ng-class="{selected : vote.id === idSelectedVote}"> 
     <li class="created"> 
      {{vote.created|date}} 
     </li> 
     <li class="ip"> 
      {{vote.ip}} 
     </li> 
     <li class="status"> 
      {{vote.status}} 
     </li> 
    </ul> 
相關問題