<view wx:for="{{seatnum}}" >
<view wx:if="{{item.status == '0'}}">
<icon id="{{item.objectId}}" type='success' bindtap="click" color='green'></icon>
</view>
<view wx:elif="{{item.status == '1'}}">
<icon id="{{item.objectId}}" type='success' bindtap="click" color='red'></icon>
</view>
<view wx:elif="{{item.status == '2'}}">
<icon id="{{item.objectId}}" type='success' bindtap="click" color='orange'></icon>
</view>
<view wx:else>
<icon id="{{item.objectId}}" type='success' bindtap="click" color='grey'></icon>
</view>
</view>
从数据库中取得数据后,根据数据库中的属性让icon显示不同的颜色,求问:怎么可以在点击icon时,改变它的颜色?或者这个代码可以怎么修改来得到我想要的效果
<view wx:for="{{seatnum}}" wx:key="objectId"> <view> <icon data-index="{{index}}" type="success" color="{{item.status == '0' ? 'green' : item.status == '1' ? 'red' : item.status == '2' ? 'orange' : 'grey'}}" bindtap="click" /> </view> </view> click (e) { let index = parseInt(e.currentTarget.dataset.index); this.setData({ [`seatnum[${index}].status`]: "你要的颜色?" }); }
js里面click函数里,this.setData改变item.status