Tempo js - Rendering an array of strings or simple objects, referring to “this” in the template

StackOverflow https://stackoverflow.com/questions/10132718

  •  31-05-2021
  •  | 
  •  

Pregunta

Just getting started with Tempo javascript templating engine. In all examples in the documentation, the collection you are iterating over is an array of objects or arrays, and in the templates you refer to property names (i.e. {{name}}) or array indexes (i.e. {{[0]}}). But what if I'm iterating over an array of simple types like strings? Is there a way to refer to the the object itself in the template? something like {{this}}?

For example:

var data = [ "All", "Europe", "Asia", "America", "India"];
Tempo.prepare("locations").render(data);

Now I want to render my data to a list in a template:

<ul id="locations">
   <li data-template>
       {{?????}}
    </li>
</ul>

How do I refer to an individual array item in the example above?

¿Fue útil?

Solución

Thanks for pointing this out Todd. With Tempo 1.8+ you can refer to the object being iterated using:

{{.}}

For example:

<ul id="locations">
   <li data-template>
       {{.}}
    </li>
</ul>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top