KnockoutJs v2.3.0 : “cannot apply bindings multiple times to the same element”

橙三吉。 提交于 2019-12-08 08:30:16

问题


Problem:

In an existing application, I'm adding a new feature which uses knockout to display a grid and some additional information. I load some of the data at the start and prepare subscriptions which load other data using ajax, create viewmodel in Razor view to inject server-side variables, and then bind it (it does not matter if I pass html node or not, I have same problem). Upon page load, "cannot apply bindings multiple times to the same element" error appears in console, and all of the html elements which use if, with or template bindings are empty.

The only occurrences of "applyBindings" in entire project are in my view, and in knockout source. Debugging shows that it is called twice, both times from $(document).ready

When I remove apply bindings from code, and call it later manually using console, it works.


回答1:


Answer is already on SO: jQuery $(document).ready () fires twice

Theme of the application was moving/manipulating html elements, and tag with viewmodel initialization was inside same html view which was manipulated later. Moving to separate section which is rendered in head solved problem.



来源:https://stackoverflow.com/questions/18953280/knockoutjs-v2-3-0-cannot-apply-bindings-multiple-times-to-the-same-element

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