Vant Weapp

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
      },
相关推荐
营赢盈英7 天前
Azure web app has no access to openai private endpoint in virtual network
azure·openai api·web app·webapp·webapps·virtual network
xxxxfdsax8 个月前
将WAP网站封装成App体验的全新策略
uni-app·web app·webapp