简体   繁体   中英

Mustache.js render technique

i am trying to use mustache.js to render some JSON in the browser. What i want to do is:

<li>
   <span class="label">Location: </span> 
   {{#locations}}
     {{.}}<span class="social-small-size "></span>
   {{/locations}}
</li>

The locations is a js array

[["Pendéli, Attiki, Greece", "facebook"], ["Greece", "linkedin"]]

Initially i tried to use {{%IMPLICIT-ITERATOR iterator=loc}} in my attempt to split the data in the view. So i the actual rendering code was

{{loc[0]}}<span class="social-small-size {{loc[1}}"></span>

But that did nt work altough the loop worked and i got 2 spans but without any content. I think the PRAGMA is what I need but I didn 't figure it out. Any hints ? :)

The answer is quite simple, do not use arrays in array. You should uses hashes. The above code should work as

{{#locations}}
    {{value}} <span class='social-small-size {{network}}'></span>
{{/locations}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM