如何同时渲染我的视图和JSON输出?

时间:2019-05-19 16:47:16

标签: node.js json express couchdb

我需要以JSON格式显示来自CouchDB的信息。

我正在尝试将返回的JSON传递到我的翡翠视图模板,并同时渲染视图。

但是我收到一个错误。

如果我仅尝试显示JSON输出,则显示正确。


var renderEmployeersPage = function(req, res, responseBody){
  res.render('employeers-list', {
    title: 'Кариерен помощник',
    pageHeader: {
      title: 'Кариерен помощник',
      strapline: 'Открий идеалния кандидат за работа'
    },
    sidebar: "Този сайт ще ви помогне да намерите подходящия кандидат за вашата позиция."
   });
};

module.exports.getEmployeer=function(req,res){
  db
  .getDoc('7c2310051f2587bc4782325f06002a91', function(err,doc) {
    if (err) throw new Error(JSON.stringify(err));
    console.log("Fetched my new doc from couch");
    console.log(doc);
    //renderEmployeersPage(req,res); --it renders the view
    res.json(doc);

  });

    extends layout

    include _includes/sharedHTMLfunctions

    block content
      #banner.page-header
        .row
          .col-lg-6
            h1= pageHeader.title
             small  #{pageHeader.strapline}
      .row
        .col-xs-12.col-sm-8
          .row.list-group
            each employeer in employeers
              .col-xs-12.list-group-item
                h4 
                  a(href="/employeers")= employeer.name
                  small  
                    +outputRating(employeer.rating)
                  span.badge.pull-right.badge-default= employeer.distance
                p.address= employeer.address
                p
                  each facility in employeer.facilities
                    span.label.label-warning= facility
                     
        .col-xs-12.col-sm-4 
          p.lead= sidebar

I expect to render my view and the JSON data.

0 个答案:

没有答案