extjs - Set ViewModel data value from inside timeout doesn't update the View -
i need update viewmodel
data inside settimeout
callback function, doesn't work. looks i'm running problem similar happens when need update data value in angular outside angular , need call $scope.apply()
, in extjs' way.
here's code:
ext.define('web.view.taskbar.clock.clockcontroller', { extend: 'ext.app.viewcontroller', alias: 'controller.taskbar-clock', init: function() { var me = this; // works var time = new date(); me.getviewmodel().data.time = time.gethours() + ':' + time.getminutes() + ':' + time.getseconds(); // doesn't work var timer = function() { settimeout(function() { var time = new date(); me.getviewmodel().data.time = time.gethours() + ':' + time.getminutes() + ':' + time.getseconds(); timer(); }, 1000); }; timer(); } });
edit: updated working code
ext.define('web.view.taskbar.clock.clockcontroller', { extend: 'ext.app.viewcontroller', alias: 'controller.taskbar-clock', init: function() { var vm = this.getviewmodel(); var timer = function() { settimeout(function() { var time = new date(); vm.set('time', time.gethours() + ':' + time.getminutes() + ':' + time.getseconds()); timer(); }, 1000); } timer(); } });
you need call setter method: link.
vm.set('time', 'x');
Comments
Post a Comment