2012-03-16 5 views
1

私は以下のようなコードを用意しています。停止ボタンをクリックすると、bExitフラグが1に設定されます。コンソールでは、単語の消去が2秒間隔で繰り返されます。タイムアウトをクリアして、単語のクリアが繰り返されないようにするにはどうすればよいですか?grepのcleartimeout?

//stop playback 
$('.stop').live('click', function() { 
    bExit = 1 
    console.log("stopping..."); 
    clearTimeout(timer0); 
}); 

var timer0; 
var obj = $.grep(thedata, function (e, index) { 
    timer0 = setTimeout(function() { 
     if (bExit == 1) { 
      console.log("clearing..."); 

      //$(".nodeCount,.statInfo,.theborder").hide(); 
      clearTimeout(timer0); 

      return 
     } 
    }, 2000 * index); 
}); 

答えて

0

MDN documentationで述べたようにwindow.setTimeoutwindow.clearTimeoutを使用してみてください。

+0

違いがありません – Rob

+0

すべてのタイマーを保存するために、1つの変数 'timer0'を使用している可能性がありますか?あなたが 'var timer0 = setTimeout(function(){'? –

+0

がgrep/loopのための1つのタイマーにすぎないと言ったとしたら? – Rob