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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退