获取form表单中的radio数据,只能获取最后一个循环的radio?
js代码
data{
datas:[
{ "item": "你是个忧心忡忡的人吗?", "answer1": "是", "answer2": "否" },
{ "item": "你是否觉得人们为了未来有保障,而在储蓄和保险方面花费的时间太多了?", "answer1": "是", "answer2": "否" },
{ "item": "当你看到小孩(或动物)受折磨时是否感到难受?", "answer1": "是", "answer2": "否" }
]
},
formSubmit: function (e) {
console.log('form发生了submit事件,携带数据为:', e.detail.value);
this.setData({
allValue: e.detail.value.answer
})
},
formReset: function () {
console.log('form发生了reset事件')
},
wxml代码
<form bindsubmit="formSubmit" bindreset="formReset">
<view wx:for="{{datas}}">
<view>{{index+1}}{{item.item}}</view>
<view class="section section_gap">
<radio-group name="answer" bindchange="radioChange">
<label>
<radio value="radio1" />是</label>
<label>
<radio value="radio2" />否</label>
</radio-group>
</view>
</view>
<radio-group name="radio-group">
<label><radio value="radio1"/>radio1</label>
<label><radio value="radio2"/>radio2</label>
</radio-group>
<view>
<button formType="submit" bindtap=" answer2db">提交</button>
<button formType="reset">取消</button>
</view>
</form>