Почему массив апостроф-страниц _children всегда пуст? - PullRequest
0 голосов
/ 28 марта 2019

Я пытаюсь, чтобы дочерние страницы апострофов появлялись в моем объекте навигации - однако массив _children всегда пуст.На моей странице есть дочерние страницы, настроенные через пользовательский интерфейс Pages.

Мой 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 () действительно включал дочерние страницы?

1 Ответ

1 голос
/ 29 марта 2019

Решено ..

Мне нужно было добавить 'rank: 1, path: 1, level: 1' к проекции согласно этой странице в документации: https://apostrophecms.org/docs/tutorials/howtos/children-and-joins.html#projections-and-children

...