1
我使用的是collections2和meteor-cfs-autoform的模式,並使用cfs:gridfs存儲適配器包上傳和顯示圖像,但無法在模板中顯示圖像。可以爲您請告訴我我在做什麼錯誤及其解決方案。collections2和meteor-cfs-autoform來上傳和顯示圖像
collections.js
Recipes = new Mongo.Collection('recipes');
Reviews = new Mongo.Collection('reviews');
RecipesImages = new FS.Collection("recipesImages", {
stores: [new FS.Store.GridFS("recipesImages")]
});
RecipesImages.allow({
insert: function(userId, doc) {
return true;
},
update: function(userId, doc, fieldNames, modifier) {
return true;
},
download: function(userId) {
return true;
},
fetch: null
});
Recipes.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Recipe Name",
max: 100
},
ingredients: {
type: [Object],
minCount: 1
},
"ingredients.$.name": {
type: String
},
"ingredients.$.amount": {
type: String
},
description: {
type: String,
label: "How to prepare ",
},
time: {
type: Number,
label: "Time (Minutes)",
},
image: {
type: String,
autoform: {
afFieldInput: {
type: "cfs-file",
collection: 'recipesImages',
label: 'Recipe Picture'
}
}
}
}));
recipes.js
Template.recipes.helpers({
'showRecipes':function(){
return Recipes.find();
},
'images': function() {
return RecipesImages.findOne({_id:id}) ;
}
})
recipes.html
<template name="recipes">
{{#each showRecipes}}
<div class=" col-md-4">
<div class="panel panel-default mb " >
<div class="panel-image">
<img src="{{this.url }}" class="panel-image-preview" />
</div>
<div class="panel-body">
<h4>{{name}}</h4>
<p>{{description}}</p>
</div>
<div class="panel-footer text-center" >
<p>its footer </p>
</div>
</div>
</div>
{{/each}}
</template>
CFS:未添加UI和我現在又增加了。它仍然沒有工作。我是初學者和自學流星,我已經花了最後4天弄清楚如何顯示圖像,但仍然沒有成功。你可以看看我的源代碼,並請告訴我解決方案,因爲我現在認爲我是非常接近解決它。 https://github.com/soni1/foody @Lucas Blancas – Waqar
@waqar,我克隆了你的git項目並能解決這個問題。看到我上面更新的答案。重要的變化是{{#with FS.GetFile「recipesImages」image}}。請注意,我也刪除了recipe.images幫手,因爲這不再需要。 –