简体   繁体   English

流星渲染来自嵌套嵌套集合的数据

[英]Meteor render data from embeded, nested collection

I've been trying to get data out of a nested collection without any luck, besides using the dot notation from the html nothing seems to work. 我一直在尝试从嵌套集合中获取数据而没有任何运气,除了使用html中的点表示法外,其他方法似乎都无效。

What I want basically is to soley fetch the data I need from a nested collection. 我基本上想要的是从嵌套集合中获取所需的数据。 I'm trying to build a file upload for images and audio files and then a simple way to use the files. 我正在尝试为图像和音频文件构建文件上传,然后使用文件的简单方法。 I'm using the cfs:standard-packages and cfs:filesystem packages. 我正在使用cfs:standard-packages和cfs:filesystem软件包。

The code below shows a working example of what I don't want, eg fetching the whole file object and retrieving the data in the html. 下面的代码显示了一个我不想要的工作示例,例如,提取整个文件对象并检索html中的数据。 If I could use the dot notation in the mongo command somehow would be perfect. 如果我可以在mongo命令中使用点表示法,那将是完美的。 I also could settle for _each but I would prefer fetching just the data I need on each db call. 我也可以满足_each的要求,但我更希望仅获取每个数据库调用所需的数据。 As you can see I'm passing an id for the whole file object here. 如您所见,我在此处传递整个文件对象的ID。 Uploads.find({_id:Session.get('getpic')}); BTW, the actual file is stored in a folder on my local server. 顺便说一句,实际文件存储在本地服务器上的文件夹中。

The collection: 集合:

 {
    "_id" : "DXFkudDGCdvLpPALP",
    "original" : {
        "name" : "drink.png",
        "updatedAt" : ISODate("2015-04-30T07:14:56.000Z"),
        "size" : 127944,
        "type" : "image/png"
    },
    "uploadedAt" : ISODate("2015-07-11T21:53:32.526Z"),
    "copies" : {
        "uploads" : {
            "name" : "drink.png",
            "type" : "image/png",
            "size" : 127944,
            "key" : "uploads-DXFkudDGCdvLpPALP-drink.png",
            "updatedAt" : ISODate("2015-07-11T21:53:32.000Z"),
            "createdAt" : ISODate("2015-07-11T21:53:32.000Z")
        }
    }
}

HTML HTML

<template name="renderImages">
{{#each showpic}}
    <img width="300" height="300" src="/projectuploads/{{copies.uploads.key}}"/>
{{/each}}

Javascript: 使用Javascript:

Template.renderImages.helpers({
    showpic: function() {
    return Uploads.find({_id:Session.get('getpic')});
  }
});

specify the returned fields in the find query like so find查询中指定返回的字段,如下所示

return Uploads.find({_id:Session.get('getpic')}, { fields: {'copies.uploads.key': 1} } );

but a word on that. 但是一个字。 here you query minimongo (on the client), which is in the browsercache so it's basically free. 在这里,您可以在浏览器缓存中查询minimongo(在客户端上),因此基本上是免费的。 take care to publish only those fields to the client that you actually want there. 请注意仅将这些字段publish到您实际希望在那里的客户端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM