1

我有一个模式声明为:

JobSchema = new SimpleSchema({
    responsibilities: {
        type: [String],
        optional: true
    },
    'responsibilities.$': {
        min: 2,
        autoform: {
            afFieldInput: {
                class: 'form-control'
            },
            placeholder: 'E.g. "Build tools according to specifications"'
        }
    }
});

我还有一个 UI 助手声明为:

Template.registerHelper('currentFieldValue', function (fieldName) {
    return AutoForm.getFieldValue('insertJobForm', fieldName) || '';
});

我有一个模板,我使用这个助手来生成表单预览。它对除数组字段之外的所有字段都有效。什么都没有被渲染。有任何想法吗?

{{# if currentFieldValue "responsibilities"}}
    <h3>Responsibilities</h3>
    {{{currentFieldValue "responsibilities"}}}
{{/if}}
4

1 回答 1

0

一个快速而肮脏的解决方法:

job_create.js

Template.jobCreate.helpers({
    responsibilities: function() {
        var formData = AutoForm.getFormValues('insertJobForm');
        return formData.insertDoc.responsibilities || [];
    }
});

job_create.html

{{# if responsibilities}}
    <h3>Responsibilities</h3>
    {{responsibilities}}
{{/if}}
于 2015-01-12T16:07:13.843 回答