Автоформа с CollectionFS для метеора

Я использую aldeed:autoform aldeed:collection2 cfs:autoform cfs:standard-packges cfs:gridfs

Daycares = new Mongo.Collection('daycares');

Daycares.attachSchema(new SimpleSchema({
  daycarename: {
    type: String,
    label: "Daycare Name",
    max: 100
  },
  address: {
    type: String,
    label: "Address",
    max: 100
  },
  position: {
    type:[Number],
    optional: true,
    decimal: true
  },
  yib: {
    type: Number,
    label: "Years in Business"
  },
  contactname: {
  type: String,
  label: "Contact Name",
  max: 100
  },
  phone: {
    type: Number,
    label: "Phone Number"
  },
  licensed: {
    type: Boolean,
    label: "Licensed?"
  },
  description: {
    type: String,
    label: "Description"
  },
  website: {
    type: String,
    label: "Website",
  },
  imageId: {
    type:String
  },
    userId: {
    type: String,
    optional: true,
    autoValue: function () {
      return this.userId;
    }
  }
}));

Images = new FS.Collection('images', {
  stores: [new FS.Store.GridFS('imagesStore')]
});

Затем HTML:

  {{#autoForm collection="Daycares" id="insertDaycareForm" buttonContent="Create"}}
    <fieldset>
        {{> afQuickField name="daycarename"}}
        {{> afQuickField name="address"}}
        {{> afQuickField name="yib"}}
        {{> afQuickField name="contactname"}}
        {{> afQuickField name="phone"}}
        {{> afQuickField name="licensed"}}
        {{> afQuickField name="description" rows=4}}
        {{> afQuickField name="website"}}
        {{> afQuickField name="imageId" type="cfs-file" collection="images"}}

    </fieldset>
    <button type="submit" class="btn btn-success">Create</button>
    {{/autoForm}}

Но затем, когда я пытаюсь показать отдельную страницу для элемента, я не уверен, как на самом деле показать изображение. Я выполнил инструкции на гитхабе до чая.

Это HTML:

<template name="SingleDaycare">
  {{daycarename}}
  {{address}}
  {{yib}}
  {{contactname}}
  {{phone}}
  {{description}}
  <img src="{{imageId}}" />
</template>

Любая помощь была бы замечательной!


person Dillon Raphael    schedule 24.08.2015    source источник


Ответы (1)


Помощник должен сделать свое дело:

Template.SingleDayCare.helpers({
  imageUrl: function(){
    return Images.findOne({_id: this.imageId}).url();
  }
});

Предполагая, что ваши изображения находятся в коллекции Images.

Затем в html:

<img src="{{imageUrl}}" />
person Michel Floyd    schedule 25.08.2015