为什么撇号页_children数组始终为空?

时间:2019-03-28 15:23:56

标签: node.js apostrophe-cms

我试图使撇号页面的子代出现在导航对象中-但是_children数组始终为空。我的页面确实具有通过前端页面UI设置的子页面。

我的lib / modules / apostrophe-pages模块的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属性是通过撇号定制页面设置的:

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 个答案:

答案 0 :(得分:1)

解决了..

我需要根据文档中的以下页面,将DetailsDAO package dao; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; public class DetailsDAO { private Connection con = null; public DetailsDAO() { try { System.out.println("Loading db driver..."); //Class.forName("org.apache.derby.jdbc.ClientDriver"); System.out.println("Driver loaded..."); con = DriverManager.getConnection( "jdbc:derby://localhost:1527/SOA4_DB", "sean", "sean"); } catch (SQLException ex) { System.out.println("Exception!"); ex.printStackTrace(); } } public static void main(String[] args) { DetailsDAO dao = new DetailsDAO(); // connect to db List<Details> detailsList = dao.getAllDetails(); for (Details d : detailsList) { System.out.println(d); } } public List<Details> getAllDetails() { List<Details> detailsList = new ArrayList<>(); try { // SQL in here PreparedStatement ps = con.prepareStatement( "SELECT * FROM APP.DETAILS" ); ResultSet rs = ps.executeQuery(); while (rs.next()) { Details d = new Details (rs.getInt("ID"), rs.getString("NAME"), rs.getInt("AGE"), rs.getTimestamp("TIMESTAMP")); detailsList.add(d); } } catch (SQLException ex) { System.err.println("\nSQLException"); ex.printStackTrace(); } return detailsList; } public Details getDetails(int id){ Details details = null; try{ // SQL in here PreparedStatement pstmt = con.prepareStatement( "SELECT ID, NAME, AGE, TIMESTAMP, " + "FROM APP.DETAILS " + "WHERE (ID = ?)"); pstmt.setInt(1, id); ResultSet rs = pstmt.executeQuery(); // move the cursor to the start if(!rs.next()){ // !F == T return null; } // we have at least one record details = new Details (rs.getInt("ID"), rs.getString("NAME"), rs.getInt("AGE"), rs.getTimestamp("TIMESTAMP")); } catch (SQLException ex) { Logger.getLogger(DetailsDAO.class.getName()).log(Level.SEVERE, null, ex); System.err.println("\nSQLException"); ex.printStackTrace(); } return details; } } 添加到投影中:https://apostrophecms.org/docs/tutorials/howtos/children-and-joins.html#projections-and-children