【问题标题】:AutoForm- Access value of array of object's properties inside templateAutoForm-访问模板内对象属性数组的值
【发布时间】:2015-10-29 07:40:30
【问题描述】:

我在我的架构中定义了一个对象数组,现在想在我的模板中显示对象属性,但不知道如何做。

   ingredients: {
            type: [Object],
            minCount: 1
        },

    "ingredients.$.name": {
    type: String
        },
    "ingredients.$.amount": {
    type: String
    }

并尝试在模板中访问它们

<li class="list-group-item">{{ingredients.$.name}} - {{ingredients.$.amount}}</li>

所以你能帮我如何在模板中访问它们。

【问题讨论】:

    标签: javascript meteor meteor-autoform


    【解决方案1】:

    假设我理解正确并且您有一个包含该架构中数据的集合,那么您只需要获取该数据(例如,使用名为 ingredients 的帮助程序),然后在您的模板中使用 #each

    {{#each ingredients}}
       <li class="list-group-item">{{name}} - {{amount}}</li>
    {{/each}}
    

    【讨论】:

    • 好成分不是由它自己收集,而是收集食谱的一部分。当用户点击页面上显示所有食谱列表的食谱时,会打开一个特定页面,只针对点击的食谱它的完整细节。在那个页面上我也想显示它的成分列表。你可以看看我的源代码github.com/soni1/foody
    • 我认为通过我的回答和文档,您应该可以解决剩下的问题。想想帮助函数需要返回什么。我不会阅读你的整个代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    • 2019-10-15
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多