[英]JavaScript: How do I access the prototype of an object inside another object?
[英]How do I access an object inside of an object in javascript
這是要返回的對象。
Object:
contributors_enabled: false
created_at: "Sat Apr 18 02:20:51 +0000 2009"
...
status: Object
...
verified: false
如您所見,有2個對象。 父對象然后是其中的對象稱為“狀態”。
在javascript中,如何訪問“狀態”對象。
我已經嘗試過返回null的object.status
。
實碼:
function get_data( $id ) {
global $tmhOAuth;
$code = $tmhOAuth->request( 'POST', $tmhOAuth->url('1/users/lookup.json', ''), array( 'user_id' => $id ) );
if ( $code == 200 ) {
$data = json_decode($tmhOAuth->response['response'], true);
return $data;
} else {
outputError($tmhOAuth);
}
}
if ( !empty( $_POST ) && !is_null( $_POST ) ) {
extract( $_POST ); //imports $id;
$data = get_data($id);
exit(json_encode($data));
}
$.post(
'/twitauth/app.php',
data,
function( response ) {
console.log( response );
},
'json'
);
您將需要發布實際的代碼,因為這兩個代碼都應該起作用:
object.status
object["status"]
如果這些都不起作用,則說明您以某種方式錯誤地定義了對象,或者該對象內的對象是私有的。
您可以使用引用n層對象.
操作員,沒問題。
這是一個例子
var myobj = {
'a' : 1,
'b' : 2
};
var foobar = {
'foo' : 'bar',
'status' : myobj
};
console.log(foobar.status.a);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.