Mustache(icanhaz) iterating array of arrays

给你一囗甜甜゛ 提交于 2020-01-01 05:04:14

问题


In mustache if we have an array like :

var a = [1,2,3,4];

We can create template like:

{{#a}}
{{.}}
{{/a}}

to iterate over it. Now if we have some thing like

var a = [[1,2], [3,4], [5,6]]

Can we create a template like:

{{#a}}
key is {{0th element}} and the value is {{1st element}}
{{/a}}

回答1:


Tried out things and got the solution: We can do the following:

var htm = '{{#names}}'+
            '<p> value="{{0}}" key = "{{1}}"</p>'+
          '{{/names}}';
ich.addTemplate('formNameOptionsHTML',htm);
var arr =[[0,1],[10,11],[20,21]];
var htm = ich.formNameOptionsHTML({names:arr});
$('body').append(htm);

Here is the jsfiddle link to it.



来源:https://stackoverflow.com/questions/9582722/mustacheicanhaz-iterating-array-of-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!