1

需要咨询JS绝地。情况:我得到了带有 USER_ID 的数组,需要调用社交网络功能才能在他们的墙上发帖。所以我需要启动 wallpost 功能,听听它的答案,然后继续迭代我的循环。我编写的代码能够将帖子留给数组中的最后一个人,到第一个,到没有以及许多其他有用的功能:s。需要你的帮助

    function showPost() {
            for(i in selFriends) {  //selFriends - massive with user_id 
                    alert(i+' '+selFriends[i]); //checkplace
                    VK.api('wall.post',{
                            owner_id:selFriends[i], //element
                            message:htmlres,  // content 
                            attachment:photoID // id of the mediacontent
                    },function(receive) {
                            showPost();
                    });
            return;
            }
    }

这段代码需要修复,因为现在它只是大量的第一个元素的迭代墙。顺便说一句,方法 VK.api 几乎类似于 Facebook UI 方法“提要”。非常感谢你 :)

4

1 回答 1

3

我不是绝地武士,但是您是否尝试通过 运行selFriends数组中的第一个索引VK.api,并在回调中调用下一个索引?然后对 selFriends 数组中的每个元素重复?

function postId(index) {
   if (index === selFriends.length) 
       return;
   VK.api('wall.post',{
       owner_id:selFriends[i], //element
       message:htmlres,  // content 
       attachment:photoID // id of the mediacontent
       },function(receive) {
           postId(index + 1);
   });
}

进而

function showPost() {
    postId(0);     
}
于 2012-01-06T17:43:49.670 回答