node.js Express - How to get partial views asynchronously

前端 未结 2 2085
借酒劲吻你
借酒劲吻你 2021-02-06 13:50

I\'ve got a layout - navigation menu. In express tutorials theres only old-school pages loading. whole old page is thrown away and a new one is downloaded with all layouts,views

2条回答
  •  悲哀的现实
    2021-02-06 14:01

    You can also use res.partial() which is specifically for rendering partials.

    Here is a sample of its usage, where 'browse.jade' is name of the template:

    exports.browse = function(req, res){
      var Contact = mongoose.model('Contact');
      Contact.where({}).asc('surname', 'given_name', 'org').run(function(err, results) {
        res.partial('browse', { 
            locals: { data: results }
        });
      });
    };
    

提交回复
热议问题