1

I'm working on a facebook app with JS SDK...

I want to create a function that makes an API call to the Graph API:

This is what I got:

function a(reference){
    FB.api('/me', function(respond){            
         var it = respond.reference[0].name;
         alert(it);
    });
}

I try executing it this way but it doesn't work.

a("inspirational_people");
4

1 回答 1

0

So you’re feeding the text string "inspirational_people" into your function, and you want to access a property of the response object having that very name?

That’s quite easy, basic JavaScript syntax: Every property that you can access via object.propertyName you can also access as object["propertyName"].

So in your case, since you want to access response.inspirational_people[0].name, it’s response[reference][0].name – the actual string value of reference is evaluated at runtime, and you should end up having what you wanted.

于 2012-06-04T16:39:50.433 回答