我有两种类型的作品,一种是作者,第二种是文章。我可以显示在Apostrophe的Demo中实现的文章列表(通过在indexAjax.html中使用index.html和articles-pages)以及作者列表(通过在)。我的问题是如何使用indexAjax.html的index.html文件显示某些指定作者撰写的文章?因此,当用户单击某个作者时,他/她应该能够看到由指定作者撰写的文章列表。authors-pages/views文件如下module.exports = { extend: 'apostrophe-pieces', name: 'articles', label: 'Article', pluralLabel: 'Articles', contextual: true, addFields: [ { name: '_author', type: 'joinByOne', withType: 'author', label: 'Author', idField: 'author', filters: { projection: { title: 1, slug: 1, type: 1, tags: 1 } } },.... ]};任何帮助将不胜感激! 最佳答案 我是P'unk Avenue的Apostrophe的建筑师。您自己的解决方案中的代码有效地重新实现了我们已经拥有的功能:反向联接。您已经有一个“转发”联接(joinByOne)。因此,使用joinByOneReverse使这些项目可从“另一侧”获得。在作者模式中,您可以编写以下代码:addFields: [ { name: '_articles', type: 'joinByOneReverse', withType: 'articles', label: 'Articles', idField: 'author', filters: { projection: { title: 1, slug: 1, type: 1, tags: 1 } } }]这使得每个作者都可以使用._articles数组属性。重要的是要注意idField不会改变。我们有意使用相同的信息,以便获得相同的内容。如果愿意,还可以在该字段上设置ifOnlyOne: true,以避免在加载多个作者的索引页和其他上下文中提取该内容。查看guide to schemas以获得更多信息。关于apostrophe-cms - 如何将作品展示为其他作品?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42689975/
10-11 08:21