简体   繁体   中英

Javascript: Tabular Data Control - how to use movenext on a time interval

I have read data from a .txt file using tabular data control but what I wanted to do is to make the data change on a time interval (the recent data will be replaced by the next data).

I thought of using .moveNext() and delay, but it seems that I got the delay implementation wrong.

var rs2 = CHAR.recordset;
var delay;
function set()
{
    if(!rs2.EOF && !rs2.BOF)
    {
        var temp = "Characters/"+rs2(1);
        document.getElementById('txt').innerHTML = rs2(0);
        document.getElementById('pic').src = temp;     
    }
}
function begin()
{
    rs2.moveFirst();
    set();  
    delay = setTimeout(move(2), 1000);
}
function move(idx)
{
    switch(idx)
    {
        case 1: if (!rs2.BOF) rs2.movePrevious();
                else rs2.moveLast();
                break;
        case 2: if (!rs2.EOF) rs2.moveNext();
                else rs2.moveFirst();
                break;
    }
    set();

    if(delay)
        clearTimeout(delay);
    delay = setTimeout(move(2), 1000);
}

When delay is executed (I think), the script become unresponsive. I think it happens because it's doing too much recursion but i don't know how to fix it.

i make my another function just for this and i think it's more convenient. it can help move() to focus on its own job(which will be called later) while doing the recursive on the right interval.

here's the function:

function automove()
{               
    if (!rs2.BOF) rs2.movePrevious();
    else rs2.moveLast();
    set();

    if(delay)
        clearTimeout(delay);
    delay = setTimeout(automove, 2000);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM