G
G
grabbee2016-03-03 16:54:27
HTML
grabbee, 2016-03-03 16:54:27

Backbone/Marionette how to layout/embed templates correctly?

As I understand it, the views in both cases, when created based on a template, after being inserted into the document, are wrapped in an empty DIV. Marionette renders the resulting view into the region that it finds by the selector, and if you use the collection list, then you get a mess

<div id="#region"> -- селектор региона для марионет
  <div> -- обертка поверх шаблона вида
    <div id="#view-list"> -- содержимое шаблона для вида
        <div> -- обертка для каждого элемента списка
            <div class="list-item">текст</div>
        </div>
        <div> -- обертка для каждого элемента списка
            <div class="list-item">текст</div>
        </div>
        ...
    </div>
  </div> 
</div>

According to the docs, at the time of creating a view or list element, I must specify the selector or element class in the view class code. At the same time, this "markup information" is not in the template itself. It turns out porridge with a description of styles and markup. Please tell me how to do everything correctly and beautifully?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aen, 2016-03-09
@grabbee

Views (views) have their own container. Div is a tag or another, you decide, for this there is a `tagName` property, which by default is exactly equal to `div`. It will also be useful to mention the `className` property, thanks to which you can set the value of the `class` attribute for your view. Use these two properties. If you have some kind of root container in your template, then it is this container that you need to describe with these properties.
A region in the DOM tree is just a container where you can output something.
PS: if you give an example, I will try to fix it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question