数组遍历里多个radio-group的问题解决

对于数组的遍历的单选组合问题如下
在这里插入图片描述

			<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

							}
						})
					}
				})
			},

  1. 先将所有checked置为false
  2. 将点击的值赋值给this.radioValue
  3. 在进行比较,如果遍历数组里面跟this.radioValue相同的就将当前的对象里的checked置为true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值