我有一个模板,显示来自三个不同集合Cars
,CarPaints
和CarPaintTypes
的文档。我知道我在路由器级需要所有这些。该模板将显示Car
文档,引用Car
的所有CarPaints
以及分别引用返回的CarPaints
(认为嵌套列表)的所有CarPaintTypes
。到模板的路径需要代表Car._id
的URL中的id
。如何在路由级别将订阅的结果用于其他订阅?
无论是Cars
收集和CarPaints
收集利用Car._id
作为一个字段(它是Cars
收集和CarPaints
集合在一个领域的本地_id
),这样很容易。然而,CarPaintTypes
使用CarPaint._id
作为它所属的CarPaint
的参考。
所以我有三个出版物:
Meteor.publish('car', function(carId) {
return Cars.find({_id: carId});
});
Meteor.publish('carPaints', function(carId) {
return CarPaints.find({carId: carId});
});
Meteor.publish('carPaintTypes', function(carPaintId) {
return CarPaintTypes.find({carPaintId: carPaintId});
});
我的路线是这样的:
this.route('car', {
path: '/car/:_id',
waitOn: function() {
return [Meteor.subscribe('car', this.params._id),
Meteor.subscribe('carPaints', this.params._id)];
// Can't figure out how to subscribe to or publish
// the carPaintTypes using all the results of what gets
// returned by 'carPaints'
}
});
我的问题是CarPaintTypes
没有Car._id
作为一个字段,只是CarPaint._id
引用到CarPaint
文件。我在哪里以及如何将订阅的结果输入carPaints
,并将每个carPaint
文档返回到订阅carPaintTypes
?或者是否有办法将它们全部结合在出版物中?稍后在我的帮手中做这件事情会更好吗?由于我知道我在路由级需要什么,因此所有订阅呼叫都应在路由代码中。
在你的答案中,你只能找到一个'carPaint'文件。我问的是如何获取多个返回的'carPaint'文档,并找到与每个'carPaint'文档关联的所有'carPaintTypes'。该模板最终将显示一个嵌套树,其顶部有一个“Car”,多个“CarPaints”和每个“CarPaint”下有多个“CarPaintTypes”。 – evolross 2014-10-03 22:04:42