我是Meteor和mongo noob(现在是一个巨大的Meteor粉丝),我正在努力实现如何在Meteor中实现查找收集.
场景:
我正在做的事情:
最初我设置了我的产品架构来保存颜色数据(去标准化数据),但是当颜色更新时,它没有在排版文档上更新.我已经看到你可以使用observeChange的观察来基本上听取变化,然后进行其他更改,尽管这似乎比它需要的更复杂.有没有办法可以为添加到特定产品的所有颜色引用颜色集合,以便任何更改都反映在产品页面上?
下面是我一直在研究的一些代码.我正在使用collection2和iron:路由器,如果这有助于任何.我已经尝试连接两个集合,虽然这不是我所追求的,因为每个循环也循环颜色(不需要).
任何帮助表示赞赏.先感谢您!-克里斯
ProductPage助手:
Template.productPageTpl.helpers({
ownProduct: function() {
return this.userId === Meteor.userId();
},
productItems: function() {
return ProductCollection.find({productId: this._id});
},
colorsItems: function() {
return ColorsCollection.find({productId: this._id});
},
// This is my attempt and although give me back both collections,
// I only need to reference the colors.
productAndColorsItems: function() {
var product = ProductCollection.find({productId: this._id}).fetch();
var colors = ColorsCollection.find({productId: this._id}).fetch();
var productColorsJoin = product.concat(colors);
console.log(productColorsJoin);
return _.sortBy(productColorsJoin, function(doc) {return …Run Code Online (Sandbox Code Playgroud)