需求:当电量少于百分之20的时候,显示电量的字体显示为红色。
1:在wxml里面设置属性batStyle: style="{{item.batStyle}}"
<text style="{{item.batStyle}}" class="battery">电量:{{item.battery}}%</text>
2:当复合逻辑条件的时候,在js里面carList[i].batStyle = "color:red";
success: function(res) { const carList = res.data.list; for (let i = 0; i < carList.length; i++){ if (carList[i].battery < 21){ carList[i].batStyle = "color:red"; } } that.setData({ carList: res.data.list, }) that.setData({ leader: res.data.leader, }) if (res.data.list.length>0){ that.setData({ back:"" }) } }