sau khi người dùng click vào checkbox thì sẽ lưu vào resultObject.
nhưng em push nó vào mà ko được
var resultObject = {
'testId':"",
'question':[
]}
function displayQuestion(surveyObj){
if(!(surveyObj && surveyObj.listQuestion.length > 0)){
return;
}
var htmlArr = [];
htmlArr.push('<div id="survey-id" style="display:none">'+surveyObj.testId+'</div>')
htmlArr.push('<div id="survey-name"><h2>'+surveyObj.name+'</h2></div>');
htmlArr.push('<div>'+surveyObj.description+'</div>');
resultObject.testId.push({'testId':surveyObj.testId});
console.log(resultObject.testId);
surveyObj.listQuestion.forEach(question=>{
htmlArr.push('<div id="'+question.questionId+'" class="question">');
htmlArr.push('<h3>'+question.content+'</h3>');
htmlArr.push('<div class="answer-list">');
question.listAnswer.forEach(answer=>{
htmlArr.push('<div class="answer">');
htmlArr.push('<input type="checkbox" class="answer-input" id="answer-'+answer.answerId+'" value="'+answer.answerId+'">');
htmlArr.push('<label for="answer-'+answer.answerId+'">'+answer.content+'</label>')
htmlArr.push('</div>');
});
htmlArr.push('</div>');
htmlArr.push('</div>');
})
htmlArr.push('<button class="btn btn-success btn-next" type="button">Hoàn thành</button>');
jQuery('#survey').append(htmlArr.join('\n'));
jQuery('#survey').find('.question .btn-next').click(function(){
var questionBox = jQuery(this).closest('.question');
alert(jQuery(questionBox).find('h3').text());
var resultArr = [];
jQuery(questionBox).find('.answer-input:checked').each(function(){
resultArr.push(jQuery(this).val());
})
var resultQuestion=[];
alert(resultArr);
});
}
giao diện để mn dễ hình dung