我写信给这个收藏品:
GiftCards = new Mongo.Collection('giftcards');
GiftCards.attachSchema(new SimpleSchema({
cardType: {
type: String
},
cardValue: {
type: Number,
defaultValue: 100
},
fileId: {
type: String,
autoform: {
afFieldInput: {
type: "fileUpload",
collection: "Images"
}
}
}
}));
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "public/uploads"})]
});用AutoForm制作的表格。
{{> quickForm collection="GiftCards" id="giftCardsForm" type="insert"}}数据是写入的,但我找不到一种方法来显示与集合中的每个文档相关联的图像.我只有id (在fileId中),也没有找到正确发布它引用的特定文档的图像的方法.
发布于 2016-04-05 18:27:48
看起来,您的GiftCards集合包含了对Images集合的单个外键引用,作为fileId。这实际上与SQL类似,因为Images集合的主键在GiftCards中用作外键。
现在你要展示一张礼品卡及其相关的单张图片。
<template name="showOneGiftCard">
Type: {{type}}, value: {{value}} <img src={{url}}/>
</template>然后需要一个助手来返回图像的url:
Template.showOneGiftCard.helpers({
url: function(){
var img = Images.findOne(this.fileId); // 'this' is the data context of one GiftCard
return img && img.url(); // will return undefined if there's no attached image
}
});https://stackoverflow.com/questions/36429492
复制相似问题