需要处理的数组如下,我们需要处理成包含问题以及答案的数组。
questionList: [
{
content: 'qqqqqqqq',
imgUrl: '',
params: [
{
answerContent: 'https://tse1-mm.cn.bing.net/th/id/OIP.1IoptREZypVwmCDzulgGGwHaGU?pid=Api&rs=1',
isImg: 1,
option: 'A'
},{
answerContent: '22222',
isImg: 0,
option: 'B'
},{
answerContent: '333333',
isImg: 0,
option: 'C'
}
],
rightAnswer: [
'B'
],
score: 10,
type: 0
},
{
content: 'wwwwwww',
imgUrl: '',
params: [
{
answerContent: '33333333',
isImg: 0,
option: 'A'
},{
answerContent: '44444444',
isImg: 0,
option: 'B'
},{
answerContent: '55555555',
isImg: 0,
option: 'C'
}
],
rightAnswer: [
'A'
],
score: 10,
type: 0
}]
处理代码
let lise = []
lise = this.questionList.map((ques) => {
let obj = {}
obj.content = ques.content
obj.imgUrl = ques.imgUrl
obj.answer = ques.rightAnswer.map((item) => {
let param = ques.params.find((x) => {
return x.option === item
})
return {
answerContent: param.answerContent,
isImg: param.isImg,
option: param.option
}
})
return obj
})
这个lise就是处理成功的数据。