【发布时间】:2017-10-27 11:11:26
【问题描述】:
考虑https://github.com/englue/meteor-publish-composite给出的例子
如何在模板视图中显示嵌套的子项。我的意思是,在视图上显示帖子上的前 2 个 cmets。
我在互联网上搜索了很多在模板视图上显示的子树,但没有找到。
代码
publishComposite('topTenPosts', {
find() {
// Find top ten highest scoring posts
return Posts.find({}, { sort: { score: -1 }, limit: 10 });
},
children: [
{
find(post) {
// Find post author. Even though we only want to return
// one record here, we use "find" instead of "findOne"
// since this function should return a cursor.
return Meteor.users.find(
{ _id: post.authorId },
{ fields: { profile: 1 } });
}
},
{
find(post) {
// Find top two comments on post
return Comments.find(
{ postId: post._id },
{ sort: { score: -1 }, limit: 2 });
},
children: [
{
find(comment, post) {
// Find user that authored comment.
return Meteor.users.find(
{ _id: comment.authorId },
{ fields: { profile: 1 } });
}
}
]
}
]
});
【问题讨论】:
-
您的客户端数据库中没有实际的树。每个文档都进入其相应的集合。到目前为止,您尝试过什么,您在哪里卡住了?
标签: meteor meteor-blaze