is ko.applyBindings synchronous or asynchronous?

核能气质少年 提交于 2019-12-09 03:09:16

问题


Does the generated view exists right after you call ko.applyBindings() or does the scaffolding happen asynchronously?

Thanks!


回答1:


ko.applyBindings is a synchronous call.

There may be cases where bindings have special code to do things in a setTimeout, but this is not generally the case.

With the addition of components in Knockout 3.2, components are asynchronous. With Knockout 3.3, there will be an option to render components synchronously if the viewmodel / template is loaded.




回答2:


Knockout is synchronous. Not only the ko.applyBindings function as RP Niemeyer already said. When you set a value to an observable property which is binded to a view, you can be 100% sure that after executing

myViewModel.myObservableProperty(newValue);

your view's been updated. In fact, an observable property is a function and when you set a new value to your observable property you are simply calling a function with the new value as parameter: this function in its body will trigger synchronously the 'change' event (i don't know exactly the event's name).

Hope it helps.. sorry but my English is a bit rusty.



来源:https://stackoverflow.com/questions/14361615/is-ko-applybindings-synchronous-or-asynchronous

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!