Button 自动时间更新

Button 自动时间更新,button,sencha-touch,extjs,sencha-touch-2,clock,Button,Sencha Touch,Extjs,Sencha Touch 2,Clock,我在Sencha-2的按钮上显示当前时间。时间在更新,但只有一次。 我想要持续更新 下面是我的代码:- Ext.define("Stackoverflow.view.Demo", { extend: "Ext.Container", alias: "widget.demo", config: { items: [{ xtype: "toolbar", id: 'clockto

我在Sencha-2的按钮上显示当前时间。时间在更新,但只有一次。 我想要持续更新

下面是我的代码:-

    Ext.define("Stackoverflow.view.Demo", {
    extend: "Ext.Container",
    alias: "widget.demo",
    config: {

            items: [{
                xtype: "toolbar",
                id: 'clocktool',
                docked: "bottom",
                items: [
                    {
                        xtype: 'button',
                        itemId: "clock",
                        id:'clock',
                        text: Ext.Date.format(new Date(),'g:i:s A')

                    }
                ]
            }]

        },  

        initialize: function(){
        console.log("initializing main view");
        Ext.defer(this.refreshDate, 1000, this);

        },
        refreshDate: function() {
        console.log("refreshing date");
        var btn = Ext.getCmp('clock');
        btn.setText(Ext.Date.format(new Date(),'g:i:s A'));
        console.log("done");
        }

    });

提前谢谢。在sencha-2中显示时间的任何其他方法也受欢迎。

当包含按钮的视图启动时,只需执行以下操作:

Ext.defer(this.refreshDate, 1000, this);
然后创建一个名为refreshDate的函数:

refreshDate: function() {
  var btn = ... // get your button

  btn.setText(Ext.Date.format(new Date(),'g:i:s A'));

  Ext.defer(this.refreshDate, 1000, this);
}

希望这有帮助

我已经更新了我的代码(通过添加您的代码)。它正在工作,但只有一次。你能帮我做点什么吗?我忘了什么。您需要在refreshDate中调用refreshDate,以便创建一个无限循环。