2013-10-26 162 views
0

我得到這個對象:Javascript對象屬性未定義(但屬性設置)

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

真的很奇怪我想,還是我做錯了什麼?

回答

2

preview_size:之間的空間,所以你需要做的:

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

我建議你找創建該對象的代碼,解決什麼導致它添加一個空格在那裏。我懷疑這是設計。