带有对象数组的Javascript;Object中的属性具有Value,返回Undefined

Javascript with Array of Objects; Property in Object has Value, returns Undefined

本文关键字:Value 返回 Undefined 属性 Object 数组 对象 Javascript      更新时间:2023-09-26

所以基本上我有一个带有属性的对象数组。现在,数组距离我正在测试的特定数据集有102个元素长。#'阵列中的s 4和6通过得很好,但5有问题。我检查了这个网站和其他许多网站,发现了一个确切的问题,他们使用属性标记的解决方案不起作用。

当我检查questionList[5]时,它返回"undefined",与questionList[5].id相同。我不明白为什么。以下是问题所在:

questionList[5]: Object
    id: "questionPage-6"
    attached: ""
    options: Array[4]
    required: true
    text: "How often do all of your active members meet?"
    type: "dropdown"
    value: ""

而这个问题紧随其后:

questionList[6]: Object
    attached: ""
    id: "questionPage-7"
    required: true
    text: "How are these meeting successful and how could they be improved?"
    type: " textarea"
    value: ""

当我做questionList时,我会得到"questionPage-7"。

因为5的id是未定义的,我无法在jQuery UI中创建我试图创建的选项卡,所以我得到了错误的片段标识符,因为使用该id的div id被设置为#undefined。

问题是,您的原始JSON具有索引5中带有空格的元素的id属性,即它具有" id"而不是"id"

演示显示如果您使用questionList[5][" id"]:http://jsfiddle.net/VYwYC/

(显然,您需要修复JSON的来源。)