我有速度模板代码,我在for循环的基础上生成类名。当其中一个for循环迭代与条件不匹配时,是否可以重置div名称。 我写的代码:
#set ($size = $confs.size())
#set ( $prev = "mycontent" )
#foreach($i in [0..$size])
#if($i < $size)
</br>
<table>
<tbody>
<tr class="impact-soy" data-key="$confs.get($i).impact">
<div class=impact-$i>
<span>$confs.get($i).impact</span>
</div>
#if($prev != $confs.get($i).actor)
<div class=actors-$i style="margin-left: auto; margin-right: auto;">
<span>$confs.get($i).actor</span>
#set ($prev = $confs.get($i).actor)
</div>
#else
#end
<script>
$(document).ready(function() {
$('div.impact-$i').connections({ from: 'div.actors-$i' }).length;
var connections = $('connection, inner');
setInterval(function() { connections.connections('update') }, 100);
});
</script>
</tr>
</tbody>
</table>
#end
#end
else块应该将类名重置为先前的if块执行类名。
答案 0 :(得分:0)
您可以执行以下操作:
#set ($prev = "Test")
<div class=actors-$i>
#if($prev != $Confs.get($i).actor)
<span>$Confs.get($i).actor</span>
#set ($prev = $Confs.get($i).actor)
#else
//do nothing and reset the div class to previous true //valid condition
$('.actor-'+$i).addClass('true'+$i);
$('.true'+$i).removeClass('actor-'+$i).addClass('actor-'+($i-1));
#end
</div>