Mustache(icanhaz)迭代数组数组 [英] Mustache(icanhaz) iterating array of arrays

查看:161
本文介绍了Mustache(icanhaz)迭代数组数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在小胡子中,如果我们有一个像这样的数组:

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}}


推荐答案

尝试了解并得到了解决方案:
我们可以执行以下操作:

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);

这里是jsfiddle的链接。

Here is the jsfiddle link to it.

这篇关于Mustache(icanhaz)迭代数组数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆