场景:

订单列表,有很多种订单状态,根据不同的订单状态要显示不同的css。

适用场景:需要根据数组下标判断不同的显示。

示例代码:

this.data.order =[{"_type":"1","custName":"李*"},{"_type":"2","custName":"李*"},{"_type":"3","custName":"李*"},{"_type":"4","custName":"李*"},{"_type":"5","custName":"李*"}];
this.data.order.forEach((item) => {
     if ([1, 3].indexOf(item._type) != -1) {
         item.status_style = 'status_success';
     } else if ([2, 5,55].indexOf(item._type) != -1) {
         item.status_style = 'status_wait';
     } else if ([4, 6, 8, 9, 14, 22, 33, 66].indexOf(item._type) != -1) {
         item.status_style = 'status_fail';
     }
})

wxml

<block wx:for='{{order}}'>
    <view class='{{item.status_style}}'>
        {{item.custName}}
    </view>
</block>

 

08-23 04:15