V
V
Vampre2019-05-02 04:38:55
JavaScript
Vampre, 2019-05-02 04:38:55

How to access a property in the jsrender template engine in a loop?

JS:

renderHtml(context) {
        let template = this._getTemplate();
        template
            .then(tmpl => {
                const shopsTmpl = jsrender.templates(tmpl);
                const html = shopsTmpl.render({selectors: this.selectors, context: context});
                document.querySelector(this.mainSelector).innerHTML = html;
            })
            .catch(err => console.log(err));
    }

Sample:
<ul class="list-group">
    {{for context}}
        <li class="{{:selectors:listItemClass}} {{:context:status}}" data-shopId="{{:context:id}}">
            {{:context:name}}
        </li>
    {{/for}}
</ul>

Because the template engine interprets :selectors as part of the context, no class is exposed. I read the doc https://github.com/BorisMoore/jsrender but damn it I can’t figure out how to refer to the property of the global object in the loop, and not to the one we are iterating over. Tell me plz!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-05-02
@Vampre

{{:~root.вашеСвойство}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question