So, I'm attempting to access the content of an 开发者_StackOverflow社区object and for the life of me can't figure out why I can't. I'm starting to believe that the object doesn't have the properties that Firebug indicates that it does. More likely than that I'm just not using the right syntax to access them.
Give the following function:
function(userData) {
console.log(userData); // statement 1
console.log(userData.t_nodecontent); // statement 2
}
Which generates the following FireBug output for statement 1
and undefined
for statement 2. (Note: Originally incorrectly indicated that I was seeing unknown
)
Is there something obvious that I'm overlooking in the way I'm attempting to reference the value of t_nodecontent
? I'm at a loss :(
unknown
means that its a Host Object, like the ones provided by ActiveXObject in IE.
If there had been no such property, you would have seen undefined
So you are accessing its property, it's just has a type not defined by ECMAScript.
Try this and write output:
for(var key in userData){
console.log(key, userData[key]);
}
The problem, you'll find, is that userData is actually [userData]! Try accessing userData[0]. I've been caught like this before (most recently today with an object property of a Dojo.Data item)... if the object is passed in an array, Firebug displays the first element of the array, rather than the array itself.
精彩评论