Icanhaz.js & Mustache.js: rendering more complex elements

I use icanhaz.js to create a JS template, and that's great! However, I cannot understand the idea of ​​creating some complex objects, and then repeat them.

Basically, in the header of the template I want to display some basic lines and then iterate the object, but first I need to pre-process this object in another template, as it contains some additional variables.

So it looks like this:

 <script id="tmpl_map" type="text/html">
     <h4>{{ equipment }}
     <h3>{{ number }}</h4>

     {{#rows}}
        {{.}}
     {{/rows}}
 </script>

My Javascript code is pretty simple for this:

view = {
    equipment: data.active.equipment,
    number: data.active.number,
    rows: function() {
        // This is where it all falls apart, I don't *get* this
        return function(text, render) {
           var rows = [];
           _.each(data.map.rows, function(el, index) {
               view = { row: el[0], has_split_next: el[1] };
               rows.push(ich.map_header(view));
           });

           return render(rows);
        }
    }
}

, , , has_split_next HTML. , ,

, , - [object Object].

+3
2

, . , , , :

rows = [{row: 'A', has_split_next: true}, {row: 'B', has_split_next: false}]

mustache.js , :

 view = { 
      equipment: data.active.equipment,
      number: data.active.number,
      rows: rows,
 }   

:

{{#rows}}
        <li class='item'>{{ row }}</li>
        {{#has_split_next}}
            <li class='split'></li>
        {{/has_split_next}}
{{/rows}}

, , , : -)

+3

, . Mustache , {#}, . , , , , , .

+1

All Articles