S
S
Sergey Pronin2016-05-12 08:21:15
backbone.js
Sergey Pronin, 2016-05-12 08:21:15

How can one make an infinite number of dependent views based on one model?

There is a form made on the backbone that works well. Based on the model, a form view is created that tracks changes to the model.

var model = new App.Models.Form();

var form = new App.Views.Form({
    model: model
    initialize: function () {
        this.render();
        this.model.on('change', this.setValue, this);
    }
});

var config.id = 12345;
$('[data-id=' + config.id + ']').html(form.el);

the view is primitively inserted into a div, like
<div data-id="12345"></div>
the task is to make it possible to insert several working views, for example, we have the same form used in the landing at the beginning and end of the page
<div data-id="12345"></div>
<!--какие-то другие дивы-->
<div data-id="12345"></div>

For some reason, the option below inserts the view only into the last of the divs, or rather, inserting it into the next one, it cuts it out from the previous one
$('[data-id=' + config.id + ']').each(function(){
         $(this).html(form.el);
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question