跳到主要内容
CNode

请教:nodeclub视图文件里的local是什么?

社区
Xxyz2k8发布于 12 年前最后回复 12 年前
346790

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

查看回复

回复 (3)

L
liyisheng#312 年前

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

web 页面: <% if(locals.bookInfo ) { %> <% } %>

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

X
xyz2k8#212 年前

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

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

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

参与回复

登录后即可参与回复。登录