小胡子使用当前数组值来索引数组

mustache use current array value to index an array

小胡子:

我有'matches'=>['foo', 'bar']。我还有:

[
    'deals'=> [
        'foo' => new Deal('name1'), 
        'bar' => new Deal('name2'), 
        'baz' => new Deal('name3')
    ]
]

我想做的是:

{{#matches}}
    {{deals}}.{{.}}.{{name}}
{{/matches}}

哪个不起作用。

这有效,只是它不像我需要的那样动态:

{{#matches}}
    {{deals.bar.name}}
{{/matches}}

有什么想法或建议吗?

您可能希望提前进行预测,以便在将代码应用于模板之前过滤交易代码中的匹配项。如果我的理解是正确的,那么您正试图在 Mustache 通常不支持的模板中嵌入匹配逻辑。

您可以过滤匹配项,也可以对每个匹配项应用布尔值 属性 来描述它是否具有匹配项。