我正在使用React和createContainer
。我正在寻找一种可以将两个电话连接在一起的方式。“链接”流星订阅
举例来说,如果我有这样的数据:
// Category
{
_id: 'ABC',
name: 'Cat 1'
}
// Item
{
catId: 'ABC',
slug: 'slug'
}
在我createContainer
,我想通过它的塞(Items.find({ slug })
)来获得Item
。然后我想转过头来,并通过item.catId
获得类别。
我想这样的事情,但它没有工作:
createContainer(({ slug }) => {
const itemHandler = Meteor.subscribe('Item.bySlug', slug);
const item = Items.findOne();
const categoryHandler = Meteor.subscribe('Category.byId', (item.id || {}).id); // also tried just item.id and got undefined for item
const category = Categories.findOne();
return { item, category };
}, Component);
我能得到item
就好了,但category
没有骰子,它仍然是不确定的。我确信我没有被动地引发任何事情,但我不确定在这种情况下正确的模式是什么,或者如果有更简化的方式。
这个包不适合你吗? https://atmospherejs.com/reywood/publish-composite – ffxsam