Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor:在集合中检索图像_Meteor_Collectionfs - Fatal编程技术网

Meteor:在集合中检索图像

Meteor:在集合中检索图像,meteor,collectionfs,Meteor,Collectionfs,我写信给这个收藏: GiftCards = new Mongo.Collection('giftcards'); GiftCards.attachSchema(new SimpleSchema({ cardType: { type: String }, cardValue: { type: Number, defaultValue: 100 }, fileId: { type: String

我写信给这个收藏:

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中)并且没有找到正确发布包含其引用的特定文档的图像的方法…

看起来您的
GiftCards
集合包含一个对
Images
集合作为
fileId
的外键引用。实际上,这与SQL非常相似,因为
Images
集合的主键在
GiftCards
中用作外键

现在,您需要显示礼品卡及其相关的单个图像

<template name="showOneGiftCard">
  Type: {{type}}, value: {{value}} <img src={{url}}/>
</template>

你查看过CollectionFS吗?是的,但我认为问题更多的是mongodb和关系-我不太了解NoSQL….使用MySQL我加入并获取我需要的…然后你能分享你为向客户端发送数据而编写的发布子代码吗?也许有点不对劲……好吧,但是如果我想用一个{{{{{{{35;每个礼品卡}}{{code>{{{{35;每个礼品卡}}}{{{>showOneGiftCard}{{/each}}来列出所有礼品卡列表,那么只需制作一个
GiftCards
帮助程序,返回
GiftCards.find()
Ok done,但是让img=Images.findOne(this.fileId)//'这是一个GiftCard give“SyntaxError:意外标识符'img'”的数据上下文,没有give:“加载资源失败:”问题可能是令牌和安全性问题。您是在Meteor 1.2还是1.3中?如果是前者,则使用
var img=
代替
let img=
。还要确保您的图像已发布并可在客户端上使用。这与代币/安全性无关。我一直在用这个图案。
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
  }
});