0

是否可以像这样从服务器中获取所有本地人:

express:

res.render('index', {
  title: 'My Title',
  p1: 1,
  p1: 2,
  p1: 3,
  p1: 4
});

jade:

 html
   head
   body
     script
        var all_locals = _.getLocals(); // all_locals => { title: 'My Title', p1: 1,    p1: 2, p1: 3, p1: 4} 
4

1 回答 1

0

您做得对,您可以将所有变量包装在一个变量中,然后使用res.render()发送。

//in express
all_locals = {
  title: 'My Title',
  p1: 1,
  p2: 2,
  p3: 3,
  p4: 4
};
res.render('upload.jade',{all_locals: JSON.stringify(all_locals)});

//in jade
var all_locals = !{all_locals};
alert(all_locals.title);
于 2013-03-24T11:30:34.903 回答