简体   繁体   English

Mustache.js渲染技术

[英]Mustache.js render technique

i am trying to use mustache.js to render some JSON in the browser. 我试图使用mustache.js在浏览器中呈现一些JSON。 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 该位置是一个js数组

[["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. 最初,我尝试使用{{%IMPLICIT-ITERATOR iterator = loc}}来拆分视图中的数据。 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. 但这并没有使整个循环都起作用,我得到了2个跨度,但是没有任何内容。 I think the PRAGMA is what I need but I didn 't figure it out. 我认为PRAGMA是我所需要的,但我没有弄清楚。 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}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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