Answer the question
In order to leave comments, you need to log in
Interaction of different models and views in Backbone?
There are two separate modules: A and B.
They have respectively A.view and A.model, as well as B.view and B.model.
On event in B.view changes B.model. But I need A.model to also change on this event. That is, it must listen to B.model events.
For this, there are controllers - separate, so to speak, entities. But in Backbone, the view is the controller. There we all listen and from there we transfer the task to change something there to the model attached to the view. But in the B.view view, A.model is not attached, they don’t know anything about each other at all.
How is this issue solved within the Backbone ideology?
How to solve it at allI understand that in this case, Backbone becomes more of a hindrance to me than an assistant. Therefore, I would like to understand how to do it ideologically correct.
Answer the question
In order to leave comments, you need to log in
How to reset external collection when rendering a view in backbone?
do not change the model from the view, it is fraught with ...
one of the options:
the Backbone object itself is extended from Backbone.Events, so it can be used as a message bus
and here we get some kind of flux ( backbonejs.org/#Events)
1) view B raises an event (trigger) on the Backbone object with sending the necessary
2) model A and B listen to this event on the bus, and update themselves
3) views A and B are subscribed to updates of their models
sometimes it is not worth passing the model to the view, it is worth having a local StateManager - > either model or dispatcher
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question