访问模板中的子字段

时间:2016-02-11 10:38:42

标签: meteor meteor-autoform

我正在使用简单架构和集合2的autoform,我已经创建了一个包含子字段的模式。我在访问模板中的子字段时遇到问题。我似乎只是得到[对象对象]。子字段是数组。有人能告诉我我错过了什么。

路径:template.html

{{#with currentUser}}
    {{#with profile}}                   
            {{#each CV}}
                {{languages}}   
            {{/each}}    
    {{/with}}           
{{/with}}

路径:schema.js

Schema.Language = new SimpleSchema({
    language: {
        type: String,  
        optional: true    
    },
    proficiency: {
        type: String,  
        optional: true    
    }
});

Schema.CV = new SimpleSchema({
    languages: {
        type: [Schema.Language],
        optional: true
    }
});

Schema.UserProfile = new SimpleSchema({
    CV: {
        type: Schema.CV,
        optional: true,
    },
});

Schema.User = new SimpleSchema({
    profile: {
        type: Schema.UserProfile,
        optional: true
    }
});

1 个答案:

答案 0 :(得分:1)

Schema.Language有几个属性,这意味着它是一个对象。试试这个:

{{#with currentUser}}
    {{#with profile}}                   
            {{#each CV}}
                {{#each languages}}  
                    {{language}}
                {{/each}} 
            {{/each}}    
    {{/with}}           
{{/with}}

您还可以使用#each CV运算符替换#with,因为CV不是架构中的数组。

相关问题