0

i feel like this should be really easy. i am feeding the properties property of the FB.ui an array that contains json objects. how can i loop through and output these objects with in the properties brackets?

this is the correct syntax:

properties: [ { text: 'value1', href: 'http://developers.facebook.com/'}, { text: 'value1', href: 'http://developers.facebook.com/'} ]

so far i can do this: properties: [ myArray[0], myArray[1] ]

and that outputs correctly, but what I want to do is dynamically output the array since it will often be a different size. i have tried for in loops and regular for loops, but i can't use those inside these brackets. probably a super easy answer, please help.

  • Not sure I follow. Maybe something like [this](http://jsfiddle.net/9fz2z/)? – Marshall Mar 09 '12 at 22:46
  • i decided to reverse and create the json string and then use the jquery $.parseJSON() in the way described in here: http://stackoverflow.com/questions/4375537/convert-json-string-to-array-of-json-objects-in-javascript – Justin Himes Mar 10 '12 at 00:14

1 Answers1

1

After looking at the Facebook docs, properties should be a JSON object and not an array. Maybe this is what you're looking for?

var myArray = [
    { text: 'value1', href: 'http://developers.facebook.com/'},
    { text: 'value2', href: 'http://developers.facebook.com/'}
];

var properties = {};
myArray.forEach(function(obj, index) {
    properties[index] = obj;
});

And then pass properties: properties in your call to FB.ui.

abe
  • 1,549
  • 1
  • 11
  • 9