使用aldeed:autoform,cfs:autoform和update-pushArray类型将文件插入Meteor中的数组

时间:2015-05-24 22:49:10

标签: meteor meteor-autoform collectionfs

我想在我的名为Modules的集合中的每个文档中构建一个上传文件数组。我使用以下软件包:

  • aldeed:自动窗体
  • aldeed:collection2
  • CFS:标准封装
  • CFS:GridFS的
  • CFS:自动窗体

收集和架构(相关部分):

Modules = new Mongo.Collection('modules');
Modules.attachSchema (new SimpleSchema({
    slides: {
        type: Array,
        optional: true
    },
    'slides.$': {
        type: Object
    },
    'slides.$.fileId': {
        type: String,
        label: "Image File"
    },
    'slides.$.time': {
        type: Number,
        label: "Time in Seconds"
    }
}));

FileStore = new FS.Collection("fileStore", {
    stores: [new FS.Store.GridFS("fileStore")]
});

FileStore.allow({
    download: function() {
        return true;
    },
    fetch: null
});

在HTML模板中:

{{#autoForm collection="Modules" scope="slides" id="addSlideForm" type="update-pushArray" doc=this}}
    <fieldset>
        {{> afQuickField name="time" type="number"}}
        {{> afQuickField name="fileId" type="cfs-file" collection="fileStore"}}
    </fieldset>
    <button type="submit" class="btn btn-primary" >Add Slide</button>
{{/autoForm}}

当我点击提交按钮时,会按预期将元素推入数组。 time值是正确的,但在fileId下只有dummyId而不是fileStore的预期_id。

在不涉及嵌套数组的应用程序的其他部分中,上载文件按预期工作。在不涉及上载文件的应用程序的其他部分中,update-pushArray表单按预期工作。复杂的是将两者结合起来。

我做错了吗?或者cfs:autoform与update-pushArray表单类型不兼容?

1 个答案:

答案 0 :(得分:0)

要使用CFS,您的#autoform类型必须是&#34; insert&#34;或&#34;方法&#34;,检查cfs文档以获取更多信息。 希望它有所帮助!

相关问题