【问题标题】:Autoform with CollectionFS for meteor使用 CollectionFS 自动生成流星
【发布时间】:2015-08-26 02:41:23
【问题描述】:

我正在使用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}}

但是当我尝试显示该项目的单页时,我不确定如何实际显示图像。我按照github上的说明去喝茶了。

这是 HTML:

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

任何帮助都会很棒!

【问题讨论】:

    标签: meteor meteor-autoform


    【解决方案1】:

    助手应该可以解决问题:

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

    假设您的图像在 Images 集合中。

    然后在html中:

    <img src="{{imageUrl}}" />
    

    【讨论】:

      猜你喜欢
      • 2015-11-23
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 2014-10-13
      相关资源
      最近更新 更多