Answer the question
In order to leave comments, you need to log in
Backbone: preloading views
There is an html page, part of which (a certain list with buttons) is processed using the backbone. (collection + model + view for the collection + view for the model). It is necessary to make sure that when the html page is initially loaded from the server, the initial state of this list is immediately displayed. That is, the list must be generated by the server, and then the backbone must pick it up.
There are no problems with the collection. I do this in the html-template of the page:
<script>
myCollection.reset({{myList}});
</script>
But I don’t enter how to pick up the views. Any ideas? Can anyone point me to a link?
Answer the question
In order to leave comments, you need to log in
The solution turned out to be simple: views have a setElement function, which can be used to bind already rendered HTML to it. She also rebinds processors.
The correct backbone-view works either with a collection or with a model.
Your view works with a collection.
In initialize, you hang up on the sync event - a call to render.
In render, you check this.collection.isEmpty()
If it is not empty, you render.
When you create a view, you immediately call render.
Then, regardless of the loading order, everything will be rendered.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question