radio,一个页面有一道选择题,在第一个页面选择C后,第二个页面初始就自动选择C,怎么解决?
发布于 7 年前 作者 xiabai 7019 次浏览 来自 官方Issues
wxml中
<view class='group'>

<view class='kaoti'>{{index + 1}} . {{datas[index].title}}</view>

<radio-group bindchange='radioChange'>

<label class='radio'>
  <radio value='1'></radio>
  <text class='exam-item'>{{datas[index].items[0].value}}</text>
</label>

<label class='radio'>
  <radio value='2'></radio>
  <text class='exam-item'>{{datas[index].items[1].value}}</text>
</label>

<label class='radio'>
  <radio value='3'></radio>
  <text class='exam-item'>{{datas[index].items[2].value}}</text>
</label>

<label class='radio'>
  <radio value='4'></radio>
  <text class='exam-item'>{{datas[index].items[3].value}}</text>
</label>

</radio-group>

</view>

<button style='width:90%' class='button1' bindtap='exam'>下一题</button>

js中
var app = getApp();//用来将本页提取到app.js中的关键

Page({

  data: {
    index:0,
    datas:[
      {
        "id":1,
        "items":[
          { "name": "A", "value": "A. 0" },
          { "name": "B", "value": "B. 1" },
          { "name": "C", "value": "C. 2" },
          { "name": "D", "value": "D. 3" }
        ],
        "kind":"1",
        "result":"C",
        "title":"1+1=?"
      },
      {
        "id": 2,
        "items": [
          { "name": "A", "value": "A. 0" },
          { "name": "B", "value": "B. 1" },
          { "name": "C", "value": "C. 2" },
          { "name": "D", "value": "D. 3" }
        ],
        "kind": "1",
        "result": "D",
        "title": "1+2=?"
      },
    ]
  },
//currIndex是下一题题号,currPage是当前页面对象
  exam:function(){
    console.log("index:"+this.data.index);
    var currPage = this;
    var currIndex = currPage.data.index + 1;
    if(currIndex==5){
      wx.redirectTo({
        url: '/pages/result/result',
      })
    }
    currPage.setData({
      index:currIndex
    });
  },

  onReady: function(){
    app.examData.examDatas = this.data.datas;
    console.log(app.examData.examDatas[0].title)
  }

 
})
回到顶部