2012-01-06 69 views
1

需要JS jedi咨询。 情况:我得到了带有USER_ID的数组,需要调用社交网络功能发布到他们的墙上。所以我需要启动wallpost函数,听取它的答案,然后继续迭代我的循环。 我写的代码能够将帖子留给数组中的最后一个人,也就是第一个,还有其他很多有用的函数:s。需要你的帮助jedisJavascript如何构建循环与非共享时间的迭代

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; 
      } 
    } 

此代码需要加以修正,因为现在它只是iterationg wall.post从大量的第1个要素。 顺便说一下,方法VK.api与Facebook UI方法'feed'几乎相似。 非常感谢你:)

+3

如果任何人都可以明白这个问题是问到底,我会很感动 – 2012-01-06 17:40:02

+1

即“大规模”的事情是一个数组,对不对? – Nikoloff 2012-01-06 17:41:13

+0

这个力量不是很强。 – Ibu 2012-01-06 17:43:09

回答

3

我没有绝地,但你试图通过VK.apiselFriends阵列运行的第一个索引,并调用回调下一个指数?然后重复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);  
} 
+0

目前没关系。对不起,浪费时间,睡不着觉:s – 966p 2012-01-06 18:30:40

+1

*这个力量很强。* – FK82 2012-01-06 18:31:40