gpt4 book ai didi

javascript - 如何在imamacros中循环数组?

转载 作者:行者123 更新时间:2023-11-28 09:03:25 24 4
gpt4 key购买 nike

我想循环“pin_board”并在每次循环时替换“boardarray”..这是下面的代码..`

var boardarray = ['board1', 'board2', 'board3', 'board4', 'board5'];

var text = 'pin_board';

for(var i in boardarray) {


pin_board = "CODE:";
pin_board += "VERSION BUILD=8300326 RECORDER=FX" + "\n";
pin_board += "TAB T=1" + "\n";
pin_board += "TAG POS=1 TYPE=BUTTON ATTR=TXT:Pin<SP>it" + "\n";
pin_board += "WAIT SECONDS=3" + "\n";
pin_board += "TAG POS=1 TYPE=LI ATTR=TXT:" + boardarray + "\n";
pin_board += "WAIT SECONDS=3" + "\n";
pin_board += "TAG POS=R1 TYPE=BUTTON ATTR=TXT:Pin<SP>it" + "\n";
pin_board += "WAIT SECONDS=5" + "\n";

}
iimPlay(pin_board);

感谢@karaxuna的回复..我修改了我的脚本并在imacros上尝试了..不幸的是,它只循环一次,而不是从board1开始,而是以baord5开始和结束。所以它只运行一次。我不知道我是否错过了什么。

这是编辑后的代码..

var boardarray = ['board1', 'board2', 'board3', 'board4', 'board5'];

var text = 'pin_board';

for(var i = 0; i < boardarray.length; i++)
{
pin_board = "CODE:";
pin_board += "VERSION BUILD=8300326 RECORDER=FX" + "\n";
pin_board += "TAB T=1" + "\n";
pin_board += "TAG POS=1 TYPE=BUTTON ATTR=TXT:Pin<SP>it" + "\n";
pin_board += "WAIT SECONDS=3" + "\n";
pin_board += "TAG POS=1 TYPE=LI ATTR=TXT:" + boardarray[i] + "\n";
pin_board += "WAIT SECONDS=3" + "\n";
pin_board += "TAG POS=R1 TYPE=BUTTON ATTR=TXT:Pin<SP>it" + "\n";
pin_board += "WAIT SECONDS=5" + "\n";

}
iimPlay(pin_board);

谢谢

最佳答案

for(var i = 0; i < boardarray.length; i++)
{
//...
pin_board += "TAG POS=1 TYPE=LI ATTR=TXT:" + boardarray[i] + "\n";
}

不要将 for in 用于数组,将其用于对象以列出其属性

编辑

var boardarray = ['board1', 'board2', 'board3', 'board4', 'board5'];

var pin_board = '';

for(var i = 0; i < boardarray.length; i++)
{
pin_board += "CODE:";
pin_board += "VERSION BUILD=8300326 RECORDER=FX" + "\n";
pin_board += "TAB T=1" + "\n";
pin_board += "TAG POS=1 TYPE=BUTTON ATTR=TXT:Pin<SP>it" + "\n";
pin_board += "WAIT SECONDS=3" + "\n";
pin_board += "TAG POS=1 TYPE=LI ATTR=TXT:" + boardarray[i] + "\n";
pin_board += "WAIT SECONDS=3" + "\n";
pin_board += "TAG POS=R1 TYPE=BUTTON ATTR=TXT:Pin<SP>it" + "\n";
pin_board += "WAIT SECONDS=5" + "\n";
}

关于javascript - 如何在imamacros中循环数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17399305/

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