Answer the question
In order to leave comments, you need to log in
What is the correct way to interact with models and collections in Backbone?
There is a task to implement tables for ordering goods on Backbone. It seems that the task is not difficult, but the problem comes when it is necessary to interact with them. Here is an example structure of what is planned to be done:
Document
|- OrderList
|- Order
| |- OrderTablesList
| |- OrderTable
|- Order
|- OrderTablesList
|- OrderTable
Answer the question
In order to leave comments, you need to log in
1. You can transfer many collections and models in a view, but in fact it is more convenient to work when the view is responsible for displaying one business entity. To solve this, nested views are used.
2. When instantiating a TableTable, a reference to the parent must be passed to it.
In order to somehow tame such a branching structure (by the way, is it really needed?), You can look for some plugin for nested models and collections, for example, this one .
For such purposes, you can make an event manager and through it organize interaction between views.
Actually, the manager itself:
This is how you can trigger an event:
This is how you can subscribe:
A detailed example can be found here
lostechies.com/derickbailey/2011/07/19/references-...
@likejavascript Your OrderTable and Order are models, right? Can you provide a code example of what you want to link?
I recommend Marionettejs. The library contains many best practices of the backbone world and is its logical continuation. Work with nested views is conveniently organized, there are ready-made solutions for rendering collections and hierarchies (just what you need).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question