Mustache 模板 - 使用数组值作为对象键

Mustache templating - Using array values as object keys

我有一个值数组和键值对对象:

var array = ["first", "second"];
var object = {
    "first":"firstvalue",
    "second":"secondValue"
};

我想遍历数组并基于值,从对象中选择值,像这样(我知道这行不通,但我正在寻找类似的方法):

{{#array}}
    <tr><td>{{.}}</td><td>{{object[.]}}</td></tr>
{{/array}}

所以输出将是:

<tr><td>first</td><td>firstvalue</td></tr>
<tr><td>second</td><td>secondValue</td></tr>

我认为这不可能,因为小胡子 "logic-less"。 也许你可以尝试用 Handlebars

换掉小胡子

Handlebars is largely compatible with Mustache templates. In most cases it is possible to swap out Mustache with Handlebars and continue using your current templates.

使用 handlerbars,您可以创建助手来处理逻辑。