我试图让撇号页面的子项出现在我的导航对象中 - 但_children数组始终为空。我的页面确实通过前端Pages UI设置了子页面。
我的lib / modules /撇号页面模块的index.js包含以下内容:
construct: function(self,options) {
// store the superclass method and call at the end
var superPageBeforeSend = self.pageBeforeSend;
self.pageBeforeSend = function(req, callback) {
// Query all pages with top_menu setting = true and add to menu collection
self.apos.pages.find(req, { top_menu: true }, {slug: 1, type: 1, _id: 1, title: 1})
.children(true)
.toArray(
function (err, docs) {
if (err) {
return callback(err);
}
req.data.navpages = docs;
return superPageBeforeSend(req, callback);
});
};
},
...
我的top_menu属性是通过apostrophe-custom-pages设置的:
module.exports = {
beforeConstruct: function(self, options) {
options.addFields = [
{
name: 'subtitle',
label: 'Subtitle',
type: 'string'
},
{
name: 'css_class',
label: 'CSS Class',
type: 'string'
},
{
name: 'top_menu',
label: 'Include In Top Menu',
type: 'boolean'
}
].concat(options.addFields || []);
}
};
这给了我top_menu设置所需的页面..但我想得到子页面..
调试代码时,我可以看到docs._children数组存在,但总是为空,即使页面有子页面...
我尝试将以下两者添加到我的app.js和我的index.js,但它不会更改结果:
filters: {
// Grab our ancestor pages, with two levels of subpages
ancestors: {
children: {
depth: 2
}
},
// We usually want children of the current page, too
children: true
}
如何让我的find()查询实际包含子页面?
解决了..
我需要根据文档中的这个页面将'rank: 1, path: 1, level: 1'
添加到投影中:https://apostrophecms.org/docs/tutorials/howtos/children-and-joins.html#projections-and-children