如何在imacros中循环数组?

时间:2013-07-01 07:24:51

标签: javascript arrays loops for-loop imacros

我想循环“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);

感谢,

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

“......不幸的是,它只循环一次,而不是从board1开始,它开始并以baord5结束。所以它只运行一次。我不知道我是否遗漏了什么。”

当然,cuz for完成工作,然后运行iimPlay(pin_board);

如果您想每次都投放 - 只需将iimPlay(pin_board);放入for

即可
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);
}

答案 2 :(得分:-1)

你们读过wiki.imacros.net吗?

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:{{board}}" + + "\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";

iimSet("board", boardarray[i])
iimPlay(pin_board);
}

http://wiki.imacros.net/iimSet