请教:nodeclub视图文件里的local是什么?
 发布于 11 年前  作者 xyz2k8  4493 次预览  最后一次回复是 11 年前  来自  

nodeclub视图文件里的local是什么?是怎么传到视图的?

3 回复
xyz2k8

这些都是自动的吗?我搜索代码没看到有如下类似的代码:

app.use(function(req, res, next){ res.locals.user = req.user; res.locals.authenticated = ! req.user.anonymous; next(); });

当然,我指的不仅仅是locals.user,代码中还有很多,比如:locals.edit_error…

liyisheng

服务端:res.render(‘book/book’,{bookInfo:bookinfo,authorInfo:authorinfo,bookChapter:bookchapter, bookSimiler:booksimiler,bookRecommends:bookrecommends});

web 页面: <% if(locals.bookInfo ) { %> <a href="/chapindex/<%= bookInfo._id %>/1" > <% } %>

这里web页面的 locals.bookInfo 对应 服务端的 bookInfo