2014-01-16 29 views
0

如何結合使用ng-repeat設置類的兩種不同方式?如何在ng-repeat中組合mouseenter/mouseleave和動態設置類?

我有以下幾點:

<div class="row" 
    data-ng-class="highlightclass" 
    data-ng-mouseenter="highlightclass='highlight'" 
    data-ng-mouseleave="highlightclass=''" 
    data-ng-repeat="a in rows" 
> 

<div class="row" 
    data-ng-class="{'t': a.correct == true, 'f': a.correct == false}" 
    data-ng-mouseenter="highlightclass='highlight'" 
    data-ng-mouseleave="highlightclass=''" 
    data-ng-repeat="a in rows" 
> 

兩個工作,但我不知道如何將它們結合起來。有沒有人有任何想法如何做到這一點?我想要的是,除了出現的t和f類之外,鼠標在行上方時,類高亮顯示取決於acorrect的值。

回答

1

你可以試試:

<div class="row" 
    data-ng-class="{'highlight': highlighted, 't': a.correct, 'f': !a.correct}" 
    data-ng-mouseenter="highlighted=true" 
    data-ng-mouseleave="highlighted=false" 
    data-ng-repeat="a in rows" 
>