Vant Weapp

本文详细描述了在使用VantWeapp开发小程序时,如何处理van-radioname组件无法接受对象的问题,以及如何在mpx中实现多层嵌套for循环。特别关注onChange事件的处理,包括针对radio-group中name为字符串的情况进行对象解析。
摘要由CSDN通过智能技术生成

Vant Weapp - 轻量、可靠的小程序 UI 组件库

van-radio name 是一个字符串,无法传对象的处理

以及 mpx 多层嵌套 for 循环处理

<view
        wx:for="{{questionList}}"
        wx:for-item="question" // item 重命名
        wx:for-index="questionIndex" // index 重命名
        wx:key="question"
      >
        <view wx:show="{{questionIndex + 1 === showIndex}}" class="hz-card">
          <text class="hz-question"
            >{{ questionIndex + 1 }}:{{ question.question }} ({{ question.type }}类问题)</text
          >
          <van-radio-group
            value="{{ answerList[questionIndex].answerItem }}"
            bind:change="onChange($event, questionIndex, question.type)"
            direction="horizontal"
          >
            <van-radio wx:for="{{question.options}}" wx:key="text" name='{{"score:" + item.score + ",text:" + item.text}}'
              >{{ item.text }} 
// name 给传一个类似对象的字符串
            </van-radio>
          </van-radio-group>
        </view>
      </view>
 onChange(event, index, type) {
        // vant-radio 中的 name 是字符串,传不了对象,这么处理事因为有的答案不同但是得分相同
        const selectData = event.detail // "score:1,text:蓝"
        this.answerList[index].answerItem = selectData
        let score = selectData.split(",")[0].split(":")[1]; // 把 "score:1,text:蓝" 中的 score 取出来
        this.answerList[index].score = parseInt(score)
        this.answerList[index].type = type
      },

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值