简体   繁体   中英

How to get value of property in javascript object?

I have an object which has status property. But I can't get the value of this property. Here is my code sample:

console.log("Resource.query()");
console.log(Resource.query());
console.log("Resource.query().status");
console.log(Resource.query().status);

Here is Chrome console: 在此处输入图片说明

As you see Resource.query().status returns undefined while Resource.query() returns the object. My question is how can I get the value of status ?

Thanks in advance.

query() is run asynchronously as noted in the tutorial (emphasis added):

$scope.phones = Phone.query();

This is a simple statement that we want to query for all phones. An important thing to notice in the code above is that we don't pass any callback functions when invoking methods of our Phone service. Although it looks as if the result were returned synchronously, that is not the case at all. What is returned synchronously is a "future" — an object, which will be filled with data when the XHR response returns. Because of the data-binding in Angular, we can use this future and bind it to our template. Then, when the data arrives, the view will automatically update.

试试这个: Resource.query()[0].status

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM