M
M
Max2014-09-05 14:22:01
JavaScript
Max, 2014-09-05 14:22:01

How to add model to View1 collection from View2 on some event?

In more detail:

there are two collections, each with its own view: View1 and View2

a2d590b4014d48e09598ad923034d5a3.png

When adding a certain model to collection 1 (View1), I need the exact same model to be added to collection 2 (View2). Until this event, collections can contain completely independent models.

The question is how to implement it?
There is an idea to throw some custom event in View1 after adding it to collection 1, and in collection 2 (View2) listen to this event and add the model accepted in event.data to the collection.

But I want to know how to do it in backbone style?

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2014-09-05
@borNfree

In collection2, listen to the add event (it's built-in) on collection1. Just the added model will come to the handler as the first argument. However, you can't just add it to collection2 (it will disappear from collection1), you have to do this.add(model.clone()).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question