Javascript对象属性未定义(但属性已设置)

时间:2013-10-26 00:18:37

标签: javascript undefined

我有这个对象:

Object {_supports_ajax: "1", _supports_bundle: "1", css_classes: Array[2], id:     "_data_afbeelding", type: "image"…}
_supports_ajax: "1"
_supports_bundle: "1"
_supports_repeatable: ""
admin_column_filter: ""
admin_column_sortable: ""
after: ""
after_id: ""
ajax: ""
args: Object
    preview_size : Array[2]
        0: 200
        1: 200
        length: 2
        __proto__: Array[0]
    __proto__: Object
css_classes: Array[2]
data_attributes: Array[0]
default_value: ""
description: "Just a little description"
explanation: "This is just a explanation explaining the field above!"
id: "_data_afbeelding"
in_bundle: ""
label: "Afbeelding"
limit: null
meta_type: "post"
name: "afbeelding"
options: Array[0]
parent: "data"
pre: ""
pre_id: ""
repeatable: ""
required: ""
show_admin_column: ""
type: "image"
underscore: "1"
__proto__: Object
}

当我记录args (console.log(Object.args))时,我只得到一个带有preview_size的对象。但是当我记录Object.args.preview_size时,我得到undefined

我觉得真的很奇怪,或者我做错了什么?

1 个答案:

答案 0 :(得分:2)

preview_size:之间有空格,所以您需要这样做:

console.log(Object.args["preview_size "])

我建议你找到创建对象的代码,并修复导致它在那里添加空间的任何东西。我怀疑它是设计的。