【问题标题】:How to access a specific index of an array in a mustache template, when that specific index is stored in another variable?当特定索引存储在另一个变量中时,如何访问 mustache 模板中数组的特定索引?
【发布时间】:2014-10-24 19:07:33
【问题描述】:

假设我有一个水果对象,我将传递给一个小胡子模板。

fruits = { 0 => {name: apple} }

我可以在胡子模板中做到这一点,一切都很好

fruits.0.name

但是如果该索引是另一个变量,如 i,我如何访问该属性?

fruits.i.name // does not work

【问题讨论】:

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

标签: templates mustache mustache.php


【解决方案1】:

你应该用小胡子来避免这种情况,并尝试使用迭代。 类似的东西:

fruits = [{name: 'apple'}]

还有迭代

{# fruits}{name}{/ fruits}

如果 fruits 依赖于您正在迭代的其他结构的 id,请尝试在该结构中包含 fruits。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-07
    • 2018-01-26
    • 2011-04-23
    • 2021-03-29
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多