简体   繁体   English

javascript这两个代码段有什么不同?

[英]javascript what's the different between this two pieces of code?

I'm new to javascript and node. 我是javascript和node的新手。 1st: 第一:

app.get('/', function(req, res){
  articleProvider.findAll(function(error, docs){
      res.render('index.jade', { locals: {
        title: 'Blog',
        articles:docs
        }
      });
  });
});

2nd 第二名

app.get('/', function(req, res){
  articleProvider.findAll(function(error, docs){
      res.render('index.jade', {
        title: 'Blog',
        articles:docs
        }
      );
  });
});

1st code is from this tutorial http://howtonode.org/express-mongodb , but doesn't work. 第一个代码来自本教程http://howtonode.org/express-mongodb ,但是不起作用。 2nd code did work, and i just don't know why? 第二代码确实有效,我只是不知道为什么? Other parts are exactly same. 其他部分完全相同。

In earlier versions of Express you needed to put the vars you wanted to make available to your Jade template in the locals field of that parameter to res.render . 在Express的早期版本中,您需要将要提供给Jade模板的vars放在该参数的locals字段中以res.render

That changed in 3.x so that all the fields of that parameter are available to the rendered template as locals. 它在3.x中进行了更改,因此该参数的所有字段都可以作为本地变量用于呈现的模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM