简体   繁体   中英

How to render one element of an array in mustache

If I have an object like

z = {"sname":"mike","lname":"michael","V":[1,2,3,4,5]};

Is there some way to specify that one element of V is to be rendered? What goes in the template in place of ????? ?

T = <p>V={{#V}}{{.}} {{/V}} but V[3]={{?????}}</p>

If this is not possible, it would be useful to know that.

I can always construct separate V_0, V_1, V_2, V-3, V_4 entries but that seems VERY ugly.

how about using lambdas to do the same. Although I am not very thorough about using partial I am guessing you could do this:

{
  "partial": function() {
    return function(array) {
      return  render(array[3]);
    }
  }
}

{{#partial}}
  {{.}}
{{/partial}}

Hope I got this right..

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