之前写过一篇博客记录了微信小程序如何实现答题样式,有一些朋友看完后想要知道选中答案后是怎么记录答案的,在这里简单处理一下逻辑,记录一下选中的答案,上篇地址如下:https://blog.csdn.net/u013982652/article/details/88121647
首先问答题的数据结构要稍微变一下,多了个index记录ABCD这些,具体如下:
data: {
quest: [{
id: 1,
type: 1, //类型,1.单选,2.多选
question: "1.你有女朋友吗?(单选)",
answers: [{
index: 'A',
content: '有'
}, {
index: 'B',
content: '没有'
}]
}, {
id: 2,
type: 1,
question: "2.目前薪资在哪个范围?(单选)",
answers: [{
index: 'A',
content: '3-6k'
}, {
index: 'B',
content: '6-8k'
}, {
index: 'C',
content: '8-10k'
}, {
index: 'D',
content: '10k以上'
}]
}, {
id: 3,
type: 2,