为什么 apostrophe-pages _children 数组总是空的?
Why is the apostrophe-pages _children array is always empty?
我试图让撇号页面的子页面出现在我的导航对象中——但是 _children 数组始终为空。我的页面确实有通过前端页面 UI 设置的子页面。
我的 index.js lib/modules/apostrophe-pages 模块包含以下内容:
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
我试图让撇号页面的子页面出现在我的导航对象中——但是 _children 数组始终为空。我的页面确实有通过前端页面 UI 设置的子页面。
我的 index.js lib/modules/apostrophe-pages 模块包含以下内容:
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