weixin_41584177 2018-01-30 01:26 采纳率: 0%
浏览 1286
已采纳

小程序开发中关于归集label的问题

在wxml中定义了若干个问题,将每个问题的答案传到数组faver中
图片说明
js:
radioChange1 : function (e) {this.data.faver[0] = e.detail.value},
radioChange2 : function (e) {this.data.faver[1] = e.detail.value},
radioChange3 : function (e) {this.data.faver[2] = e.detail.value},
radioChange4 : function (e) {this.data.faver[3] = e.detail.value},
radioChange5 : function (e) {this.data.faver[4] = e.detail.value},
请问如何中data中定义好问题和答案,在优雅的存入数组,麻烦具体一些

  • 写回答

2条回答 默认 最新

  • Go 旅城通票 2018-01-30 02:12
    关注

    之前不是回过你了。。问题都存data里面

    
    <view wx:for="{{questions}}" wx:key="id">
    <text class="text">{{index}}、{{item.name}}</text>
    <radio-group class="radio-group" bindchange="radioSelect" data-index="{{index}}">
    <label class="radio">
    <block wx:for="{{item.choices}}" wx:key="{{id}}">
    <radio value="{{item.value}}"/><text class="text">{{item.text}}</text>
    </block>
    </label>
    </radio-group>
    </view>
    
    
     Page({
      faver:[]
      , questions: [
          { name: 'aaaa', id: 1, choices: [{ text: '111', value: 1 }, { text: '222', value: 2 }] },
          { name: 'sssss', id: 2, choices: [{ text: 'fafxx', value: 1 }, { text: '22afe222', value: 2 }, { text: 'ss', value: 3 }] },
          { name: 'bbbb', id:3, choices: [{ text: 'afefef', value: 1 }, { text: 'xxafe', value: 2 }, { text: 'xxafe', value: 3 }] },
      ]},
    
      onLoad: function (options) {
      }
      radioSelect: function (e) {
        this.data.faver[e.target.dataset.index]=e.detail.value
        console.log(this.data.faver)
      }
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器