You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

const app = getApp();
Component({
properties: {
data:{
type:Object,
observer: function(data){
//console.log(data);
if(data.question_choices){
this.user_answers={};
for(var choice of data.question_choices)
this.user_answers[choice.choice_id] = choice.user_answer_boolean;
}
//console.log(this.user_answers);
}
}
},
data: {
},
methods: {
answer_choice_question: function (e) {
console.log(e, this.data);
let { detail: { value }, currentTarget: { dataset } }=e
console.log("answer_question");
console.log(value);
console.log(dataset);
let exercise_choice_id;
if (Array.isArray(value)) {
exercise_choice_id = [];
for (var i of value) {
exercise_choice_id.push(parseInt(i));
}
console.log(exercise_choice_id);
} else {
exercise_choice_id = parseInt(value);
console.log(exercise_choice_id);
}
app.api("exercise_questions.exercise_answers")({ question_id: dataset.question_id, exercise_choice_id })
.then(res => {
console.log("answer_question"); console.log(res);
if (!Array.isArray(exercise_choice_id))
exercise_choice_id = [exercise_choice_id];
for(var choice of this.data.data.question_choices){
if(exercise_choice_id.indexOf(choice.choice_id)==-1)
this.user_answers[choice.choice_id]=false;
else
this.user_answers[choice.choice_id]=true;
}
console.log(this.user_answers);
})
.catch(e => {
//console.error(e);
let {question_choices} = this.data.data;
question_choices = question_choices.map(i=>{
i.user_answer_boolean = this.user_answers[i.choice_id]
console.log(this.user_answers[i.choice_id]);
return i;
})
this.setData({"data.question_choices":question_choices})
app.showError(e)
});
},
}
})