Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top