1

I'm showing current time on a button in Sencha-2. Time is updating but only once. I want continuous updation

Below is my code:-

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

    });

Thanks in advance. Any other approach for showing the time in sencha-2 is also welcomed.

Vikal Sharma
  • 555
  • 2
  • 11

1 Answers1

2

When the view that contains the button initiates, just do something like this :

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

Then juste create a function called 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);
}

Hope this helps

Titouan de Bailleul
  • 12,920
  • 11
  • 66
  • 121