我使用wx:for 循环判断,下面伪代码
< block wx:for = "{{pageInfo}}" wx:key = "{{item.num}}" data-code = "{{item.name}}" > < view wx:if = "{{item.num == 0}}" > < view> view > </ view > < view wx:elif = "{{item.num != 0 && item.num != 2}} " > < view > view > </ view > < view wx:else> < view > view > </ view > </ block > |
能否提取出创建线的代码,每次判断只改变颜色的值就好呢?类似下面的伪码
< block wx:for = "{{pageInfo}}" wx:key = "{{item.num}}" data-code = "{{item.name}}" > < view wx:if = "{{item.num == 0}}" > < view > //color = 紫色</ view > </ view > < view wx:elif = "{{item.num != 0 && item.num != 2}} " > < view >//color = 绿色</ view > </ view > < view wx:else> < view >//color = 蓝色</ view >
</ block > |
可以在style或者class属性里做条件判断啊
我是想在wx:for里面 实现类似
int
a =0;
for
(
int
i =0;i<3;i++){
if(i == 2){
a = 1;
}
}