在微信小程序里面如何使用for循环里面的判断然后修改页面上的性别,关键是不能被覆盖掉,图中的图标颜色是循环时被覆盖了,请问js应该怎么写
根据xingming_color去判断不行?
let userList = [{ name: "张三", idcard: "110662220012120356" }, { name: "刘四", idcard: "110662220012120346" }];
for (let i = 0; i < userList.length; i++) {
if (parseInt(userList[i].idcard.substr(16, 1)) % 2 == 1) {
userList[i].color = "#0000cd";
} else {
userList[i].color = "red";
}
}
that.setData({ userList });
<view wx:for="{{userList}}" wx:key="index">
<image src="{{ic_account}}" style="background-color: {{item.color}};"></image>
<view>{{item.name}}</view>
</view>