开发者

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 n t 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}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜