2013-07-25 27 views
1

我想在使用Extjs編寫的應用程序的窗口中顯示當前時間。時間應該每隔一秒更新一次,但我不知道該怎麼做。這是我的代碼: 任何人都可以幫助我嗎?自動更新extjs3中的顯示字段值

function gettime(){ 
    var dt = new Date(); 
    dt = dt.format('h:i:s'); 
    return dt; 
}; 

var clock = { 
    layout:'form', 
    frame:false, 
    region:'center', 
    height:100, 
    width:400, 
    items:[{ 
     id: 'currtime', 
     xtype: 'displayfield', 
     fieldLabel: 'Current Time', 
     value:gettime() 
    }] 
} 

回答

1

您可以使用TaskManager爲:

// Start a simple clock task that updates a div once per second 
var task = { 
    run: function(){ 
     Ext.fly('clock').update(new Date().format('g:i:s A')); 
    }, 
    interval: 1000 //1 second 
} 
Ext.TaskMgr.start(task);