微信小程序自定义列表单选,定义一个表示为0,循环列表中index判断是否与当前的标识一样。
通过点击事件改变标识
<view class="tr {{pvalue == idx?'active':''}}" wx:for="{{4}}" wx:for-index="idx" data-name="{{idx}}" bindtap="onRadioClick">
<view class='td td-md'>AC-13-001</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<view class='td'>35%</view>
<image class="ico" src="{{pvalue == idx?'../../assets/images/dui.png':'../../assets/images/dui-w.png'}}"></image>
</view>
data: {
pvalue: '0',
},
onRadioClick(event) {
const {name} = event.currentTarget.dataset;
console.log(event.currentTarget.dataset)
this.setData({
pvalue: name,
});
},