我找到了一个script,它使用jquery将json文件转换为测验。
不幸的是,这个脚本有一个错误,也发布在这里:When one infoMode is false the quiz calculation is incorrect. Fix required.
示例JSON:
{
"question": "How old is Madonna?",
"includeInfo": true,
"info": "Madonna Louise Ciccone is an American singer, songwriter, actress, and businesswoman.",
"answers": [
{
"answer": "50",
"score": 0
},
{
"answer": "54",
"score": 0
},
{
"answer": "56",
"score": 5
}
]
}
此脚本的问题是,如果 includeInfo 设置为false,则评分不准确(得分等于零)
我这里有两个JSON,相同的数据但includeInfo是不同的:
启用includeInfo时,评分正在递增。禁用includeInfo时,分数仅为零。
这是测验的主要迭代例程 我们是否在之后向用户显示信息框 问题已得到解答。
$(data).each(function(index, object) {
$(object.questions).each(function(index, object) {
if (infoMode) {
if (currentQuestion === index) {
infoMode = false;
complete = false;
content = infoHTML(object.info);
}
} else {
if (currentQuestion === index) {
complete = false;
content = questionHTML(object.question, object.answers);
if (object.includeInfo) infoMode = true;
}
}
});
});
任何可以解决此问题的人?谢谢!
答案 0 :(得分:0)
问题出在这里,当您处于信息模式时,不要保存有关答案的任何信息。我找不到任何独特的属性,所以我用按钮的文字来捕捉它。
// ITERATION LOGIC:
var next = function ($this) {
if (infoMode) {
var userAnswer = $($this).serializeArray();
updateScore(userAnswer);
} else {
// you dont save the answer here when user clicks button.
// maybe :
if(($($this).find('button').text() == "next")){
var userAnswer = $($this).serializeArray();
updateScore(userAnswer);
} // could be the answer ?
currentQuestion += 1;
}
};
对于jsfiddles我更新了你的: 信息模式为false:https://jsfiddle.net/t4p8x02b/32/ 不是一个完美的解决方案,但它的工作原理