【问题标题】:How can I get document information in two collections?如何获取两个集合中的文档信息?
【发布时间】:2015-08-10 05:26:49
【问题描述】:

我有两个收藏,一个收藏有汽车图片(上传),另一个收藏有汽车信息(汽车),colleciton car 的 id 与carid 相同(上传收藏)。我需要这样做以显示带有图片的桌面车。

这是我的代码:

Template.Araclar.helpers({
  manset: function() {
    getData = Cars.find({});
    return Cars.find({});
    Uploads.find({
      "carid": getData._id
    });
  }
});

<div class="row">
    {{#each manset}}
    <div>{{aracmarka}}</div>
    <div style="width:400px; height:200px;" class="col-lg-3 col-md-4 col-xs-6 thumb m-t-30">
        <a>
            <img class="img-responsive" style="height:200px;" src="{{url}}" alt="">
        </a>
    </div>
    {{/each}}
</div>

注意:{{aracmarka}} 来自 Cars 集合 {{url}} 来自 Uploads 集合。

【问题讨论】:

    标签: javascript meteor meteor-helper


    【解决方案1】:

    您可以通过this 关键字访问模板助手中的数据上下文,例如:

    Template.Araclar.helpers({
        cars: function() {
            return Cars.find({});
        },
        url: function() {
            var upload = Uploads.findOne({
                "carid": this._id
            });
            return upload && upload.url;
        }
    });
    

    <div class="row">
        {{#each cars}}
            <div>{{aracmarka}}</div>
            <div style="width:400px; height:200px;" class="col-lg-3 col-md-4 col-xs-6 thumb m-t-30">
                <a>
                    <img class="img-responsive" style="height:200px;" src="{{url}}" alt="" />
                </a>
            </div>
        {{/each}}
    </div>
    

    【讨论】:

      猜你喜欢
      • 2018-07-09
      • 1970-01-01
      • 2022-10-12
      • 1970-01-01
      • 2020-08-14
      • 1970-01-01
      • 2019-07-13
      • 2014-03-31
      • 1970-01-01
      相关资源
      最近更新 更多