gpt4 book ai didi

Javascript如何用不固定的迭代时间构建循环

转载 作者:行者123 更新时间:2023-11-30 13:25:13 25 4
gpt4 key购买 nike

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

此代码需要修复,因为现在它只是迭代 wall.post 用于大量的第一个元素。顺便说一下,方法 VK.api 几乎类似于 Facebook UI 方法“feed”。非常感谢:)

最佳答案

我不是绝地武士,但你是不是想通过 VK.api 运行你的 selFriends 数组中的第一个索引,然后调用 next 回调中的索引?然后对 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);
}

关于Javascript如何用不固定的迭代时间构建循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8761991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com