Templates 当特定索引存储在另一个变量中时,如何访问mustache模板中数组的特定索引?

Templates 当特定索引存储在另一个变量中时,如何访问mustache模板中数组的特定索引?,templates,mustache,mustache.php,Templates,Mustache,Mustache.php,假设我有一个水果对象,我正在传递给一个胡须模板 fruits = { 0 => {name: apple} } 我可以在小胡子模板中这样做,一切都很好 fruits.0.name 但是如果这个索引是另一个变量,比如i,我如何访问这个属性呢 fruits.i.name // does not work 您应该避免使用胡须,并尝试使用迭代。 比如: fruits = [{name: 'apple'}] 以及迭代 {# fruits}{name}{/ fruits} 如果水果依赖于您正

假设我有一个水果对象,我正在传递给一个胡须模板

fruits = { 0 => {name: apple} }
我可以在小胡子模板中这样做,一切都很好

fruits.0.name
但是如果这个索引是另一个变量,比如i,我如何访问这个属性呢

fruits.i.name // does not work

您应该避免使用胡须,并尝试使用迭代。 比如:

fruits = [{name: 'apple'}]
以及迭代

{# fruits}{name}{/ fruits}
如果水果依赖于您正在迭代的其他结构上的id,请尝试在该结构中包含水果


希望有帮助。

您找到解决方案了吗?我现在也面临同样的问题。