我有一些代码从数据库中列出表中的项目。单击功能可在绿色和红色之间切换单元格。
<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];
}
现在,当我点击&#34;姓名&#34;或&#34;分部&#34;,我需要知道它是选择还是未选择(有效与否)?
答案 0 :(得分: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>