如何获取两个集合中的文档信息?
How can I get document information in two collections?
我有两个合集,一个合集有汽车图片(Uploads),另一个合集有汽车信息(Cars),colleciton car's id 与carid
相同(Uploads colleciton)。我需要这样做才能显示 table 辆带有照片的汽车。
这是我的代码:
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 集合。
您可以通过 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>
我有两个合集,一个合集有汽车图片(Uploads),另一个合集有汽车信息(Cars),colleciton car's id 与carid
相同(Uploads colleciton)。我需要这样做才能显示 table 辆带有照片的汽车。
这是我的代码:
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 集合。
您可以通过 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>