如何像这样从js中读取csv 并处理正确的成绩等级 注意:答案包含在xml中,并用逗号分隔
<finalquiz>
<question>
<qnumber>1</qnumber>
<qtitle>what is 2+2 </qtitle>
<a>4</a>
<b>6</b>
<c>2</c>
<d>0</d>
</question>
<question>
<qnumber>2</qnumber>
<qtitle>what is 3+3 </qtitle>
<a>4</a>
<b>6</b>
<c>9</c>
<d>3</d>
<rightanswers>a,b</rightanswers>
</finalquiz>
答案 0 :(得分:0)
正如注释中所讨论的那样,您已经解析了XML,并具有一个包含所需值的字符串,以逗号分隔。这样辛苦的工作就完成了。此时的解决方案非常简单-只需使用“ split”将逗号上的字符串分开即可。像这样:
var rightAnswersString = "a,b"; // Assume you have come up with something like this by parsing the XML
var rightAnswersArray = rightAnswersString.split (",");
for (let i=0; i<rightAnswersArray.length; i++) {
console.log (rightAnswersArray[i]); // Replace console.log with whatever you need to do with each value
}