nodeclub视图文件里的local是什么?是怎么传到视图的?
相关链接: http://expressjs.com/3x/api.html#res.locals http://expressjs.com/3x/api.html#res.render https://github.com/cnodejs/nodeclub/blob/e41c067a7c6730fad89a8cb21ccc25264c44248d/middlewares/auth.js#L6
这些都是自动的吗?我搜索代码没看到有如下类似的代码:
app.use(function(req, res, next){ res.locals.user = req.user; res.locals.authenticated = ! req.user.anonymous; next(); });
当然,我指的不仅仅是locals.user,代码中还有很多,比如:locals.edit_error…
服务端: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
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
相关链接: http://expressjs.com/3x/api.html#res.locals http://expressjs.com/3x/api.html#res.render https://github.com/cnodejs/nodeclub/blob/e41c067a7c6730fad89a8cb21ccc25264c44248d/middlewares/auth.js#L6
这些都是自动的吗?我搜索代码没看到有如下类似的代码:
app.use(function(req, res, next){ res.locals.user = req.user; res.locals.authenticated = ! req.user.anonymous; next(); });
当然,我指的不仅仅是locals.user,代码中还有很多,比如:locals.edit_error…
服务端: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