对于数组的遍历的单选组合问题如下
<view class="swiper-box-list">
<view v-for="obj in firstTabsInfo" :key="obj.productId">
<view class="secondProduct">
<view class="menu-topic-bottom-color"></view>
<text class="menu-topic-text">{{obj.name}}</text>
</view>
<radio-group @change="radioChange">
<view v-for="item in obj.productAppParamVos" :key="item.enterpriseProduceId"
class="thirdProduct">
<view>
<radio :value="item.enterpriseProduceId" :checked="item.checked"
style="transform:scale(0.7)" :disabled="!item.deliveryProCount"
color="rgba(64, 128, 255, 1)" />
</view>
<view class="thirdFont">{{item.name}}</view>
</view>
</radio-group>
</view>
</view>
radioChange(evt) {
console.log(evt, 'evt')
//先将所有checked置为false
this.firstTabsInfo.map(v => {
if (v.productAppParamVos) {
v.productAppParamVos.map(t => {
t.checked = false
})
}
})
this.radioValue = evt.detail.value
//1.将点击的值赋值给this.radioValue
//2.在进行比较,如果遍历数组里面跟this.radioValue相同的就将当前的对象里的checked置为true
this.firstTabsInfo.map(v => {
if (v.productAppParamVos) {
v.productAppParamVos.map(t => {
if (t.enterpriseProduceId == this.radioValue) {
t.checked = true
}
})
}
})
},
- 先将所有checked置为false
- 将点击的值赋值给this.radioValue
- 在进行比较,如果遍历数组里面跟this.radioValue相同的就将当前的对象里的checked置为true