我觉得这应该很简单。我为FB.ui的属性提供了一个包含json对象的数组。如何在属性括号中遍历和输出这些对象?
这是正确的语法:
properties: [ { text: 'value1', href: 'http://developers.facebook.com/'}, { text: 'value1', href: 'http://developers.facebook.com/'} ]
到目前为止,我可以这样做:properties: [ myArray[0], myArray[1] ]
这是正确的输出,但我想做的是动态输出数组,因为它通常会有不同的大小。我已经尝试过for in循环和常规for循环,但我不能使用这些括号中的循环。可能是个超级简单的答案,请帮帮忙。
发布于 2012-03-10 07:24:49
在查看Facebook docs之后,属性应该是JSON对象而不是数组。也许这就是你要找的?
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;
});然后在对FB.ui的调用中传递properties: properties。
https://stackoverflow.com/questions/9626888
复制相似问题