json Uncaught TypeError错误:无法读取属性'选择'的未定义
Error with json Uncaught TypeError: Cannot read property 'choices' of undefined
choices是json对象中的一个嵌套数组,我将这些数据放在一个多选测试序列中。当我按下该函数的触发器时,控制台显示"未捕获类型错误:无法读取未定义的"的属性"选项"。"我还有一个变量"c",当用户选择另一个检查时,该变量会发生变化,因此语句exact=exact+c将使放置函数起作用。"。
var exam0 = [
{
"question": "which is a negative number?",
"choices": [
"2",
"-2",``
"6",
"8",
],
"correctAnswer": "B",
"hint": "The one with the ' - ' negative sign"
},
......other questions****
];
功能是
function placement(x) /*x is variable used to change the question from the json object*/
{
choiceOne=$('<p>').text('A.'+exam[x].choices[0]); /*where the console points to problem*/
choiceTwo=$('<p>').text('B.'+exam[x].choices[1]);
choiceThree=$('<p>').text('C.'+exam[x].choices[2]);
choiceFour=$('<p>').text('D.'+exam[x].choices[3]);
currentQuestion=$('<p>').text(exam[x].question);
$("#honeyPot").empty().append(currentQuestion);
$("#honeyPot p").prepend(count+".");
$('#options').find('p').remove().hide();
$('#optionOne').fadeIn(250).append(choiceOne);
$('#optionTwo').fadeIn(250).append(choiceTwo);
$('#optionThree').fadeIn(250).append(choiceThree);
$('#optionFour').fadeIn(250).append(choiceFour);
}
我认为您也应该在函数中使用exam0而不是exam,因为exam0是json对象。
function placement(x) /*x is variable used to change the question from the json object*/
{
choiceOne=$('<p>').text('A.'+exam0[x].choices[0]); /*where the console points to problem*/
choiceTwo=$('<p>').text('B.'+exam0[x].choices[1]);
choiceThree=$('<p>').text('C.'+exam0[x].choices[2]);
choiceFour=$('<p>').text('D.'+exam0[x].choices[3]);
currentQuestion=$('<p>').text(exam0[x].question);
$("#honeyPot").empty().append(currentQuestion);
$("#honeyPot p").prepend(count+".");
$('#options').find('p').remove().hide();
$('#optionOne').fadeIn(250).append(choiceOne);
$('#optionTwo').fadeIn(250).append(choiceTwo);
$('#optionThree').fadeIn(250).append(choiceThree);
$('#optionFour').fadeIn(250).append(choiceFour);
}
相关文章:
- 通过属性名称选择每个td,然后给出'未定义'用于属性值
- 浏览并选择用户硬盘驱动器中的文件在IE中未定义
- jQuery:使用正确的选择器在对象上未定义
- JSON检索中选择框的额外未定义选项
- 未定义访问具有对象属性的jquery选择器
- 未定义的引用-jQuery选择器与JavaScript变量
- 来自动态生成的选择的值是“未定义的”
- 以 $_POST 为单位的未定义索引,具有多项选择
- 选择未定义,jQuery UI
- AngularJS Bootstrap UI,将数据传递到模态的问题.已选择卡未定义
- “未捕获的类型错误:无法调用未定义的方法'indexOf'”时选择jqgrid行
- <选择>的获取值显示为未定义.(棱角.js)
- 尝试选择哪个单选按钮以及何时通过代码放置它返回未定义
- 未定义的 ajax post with for 循环和字符串选择器
- 表单提交<选择>为未定义
- 反应选择未捕获类型错误:无法读取未定义的属性“值”
- 日期时间选择器引导程序获取值并将其用作输入未定义的错误
- 获取类型错误:e 未定义与 js 插件日期时间选择器
- JQuery自动完成选择未定义错误
- Angular $watch命令选择未定义的变量