嘿 friend ,我正在使用javascript sdk在jQuery facebook多 friend 选择器上的用户 friend 墙上张贴文章,但是我遇到此错误friendId.split不是函数。这是我的代码
function recommendToFriend(pic, url, friendId, fromName)
{
alert(friendId);
var friendList ;
pFriend = new Array();
pFriend = friendId.split(',');
for( x in pFriend )
{
alert(pFriend[x]);
var publish = {
method:'feed',
picture:pic,
link:url,
name:'SHARP Product Recommend',
caption: fromName + 'has recommend a product to you via Sharp Expert lounge',
};
FB.api('/'+pFriend[x]+'/feed', 'post', publish, function(resp) {
if( !response || response.error )
alert('Unable to share');
else
alert('Successfully posted to firends wall');
});
}
}
在警报框中,我得到了逗号分隔的 friend ID,因此我分别在每个用户墙上使用了分割功能后,我不知道这是怎么回事,请帮帮我
最佳答案
您可以像这样遍历JS对象
for (var key in friendid) {
var obj = friendid[key];
for (var prop in obj) {
alert(prop + " = " + obj[prop]);
}
}
希望这可以帮助
备用
for( var x in friendId )
{
alert(friendId[x]); // this would be your desired value
}