2015-08-24 80 views
0

我使用aldeed:autoform aldeed:collection2 cfs:autoform cfs:standard-packges cfs:gridfs自動窗體與CollectionFS流星

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> 

任何幫助將是巨大的!

回答

0

一個幫手應該做的伎倆:

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

假設你的圖像是Images收藏。

然後在HTML:

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