0

遅延タスクを使用して実装したカウントダウン タイマーを表示する必要があります。以下のようなコード:

var task = Ext.create('Ext.util.DelayedTask', function() {

if (sec < 1 && min > 0) {
    min--;
    sec = 60;
}
if (min == 0 && sec == 1) {
    task.cancel();
}
sec--;
Ext.getCmp('minute').setHtml(min);
Ext.getCmp('second').setHtml(sec);
console.log('minute is' + min + 'second is' + sec);

task.delay(1000);

}, this);

task.delay(1000);

上記の実装では、関数は一度だけ呼び出されます。このスレッド Auto Refresh the List in Sencha Touch Applicationでの議論を見ると、上記のコードは機能するはずです。しかし、それは機能していません。私のコードで何が間違っている可能性がありますか? ありがとう。

4

2 に答える 2

1

私の知る限り、Ext.util.DelayedTask はタスクを実行せずに遅延させるためのものです。docsでわかるように、これはフォームでの Ajax 呼び出しを遅らせるのに役立ちます。

このメソッドは、ユーザーがテキスト フィールドへの入力を終了したかどうかを検出する場合などに特に役立ちます。[..] このクラスを使用して、キー押下イベントを特定のミリ秒の間バッファリングし、その時間停止した場合にのみ実行できます。

通常の setTimeout を使用しないのはなぜですか? http://jsfiddle.net/EreaP/のようなものは完全に機能します。

于 2012-06-20T08:41:15.953 に答える
0

遅い対応:

Ext.define('MyApp.view.TimerClock', {
    extend: 'Ext.Container',
    xtype: 'timerClock',
    duration: 3 * 60 * 60, //default to 3 hour
    paused: false,
    clockIntervalHook: undefined,
    config: {
        listeners: {
            initialize: function () {
                this.start();
            }
        }
    },
    start: function () {
        var me = this,
            duration = me.duration,
            updateClock = function () {
                if (me.isPaused()) {
                    return;
                }
                me.setHtml(me.formatTime(duration--));
                if (duration <= 0) {
                    me.stop();
                }
            };
        me.clockIntervalHook = setInterval(updateClock, 1000);
        return me;
    },

    pause: function () {
        this.paused = true;
        return this;
    },

    isPaused: function () {
        return this.paused == true
    },

    resume: function () {
        this.paused = false;
    },

    restart: function () {
        this.stop();
        this.start();
    },

    stop: function () {
        clearInterval(this.clockIntervalHook);
        return this;
    },

    //format the given seconds into "HH:MM:SS" format
    //override this if you need custom behavior
    formatTime: function (seconds) {
        var hours = Math.floor(seconds / 3600);
        hours = hours <= 9 ? "0" + hours : hours;
        seconds %= 3600;
        var minutes = Math.floor(seconds / 60);
        minutes = minutes <= 9 ? "0" + minutes : minutes;
        seconds %= 60;
        seconds = seconds <= 9 ? "0" + seconds : seconds;
        return hours + ":" + minutes + ":" + seconds
    }
});

他のビューでは、単純にタイマーを追加します

{ xtype : 'timerClock' }
于 2014-07-07T19:26:44.827 に答える