2012-01-06 27 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