首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CollectionFS自动形成meteor

使用CollectionFS自动形成meteor
EN

Stack Overflow用户
提问于 2015-08-25 07:48:54
回答 1查看 95关注 0票数 0

我正在使用aldeed:autoform aldeed:collection2 cfs:autoform cfs:standard-packges cfs:gridfs

代码语言:javascript
复制
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:

代码语言:javascript
复制
  {{#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:

代码语言:javascript
复制
<template name="SingleDaycare">
  {{daycarename}}
  {{address}}
  {{yib}}
  {{contactname}}
  {{phone}}
  {{description}}
  <img src="{{imageId}}" />
</template>

任何帮助都是最好的!

EN

回答 1

Stack Overflow用户

发布于 2015-08-26 02:41:23

帮助器应该可以做到这一点:

代码语言:javascript
复制
Template.SingleDayCare.helpers({
  imageUrl: function(){
    return Images.findOne({_id: this.imageId}).url();
  }
});

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

然后在html中:

代码语言:javascript
复制
<img src="{{imageUrl}}" />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32193483

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档