问一个关于jade的问题

2013-03-27 22:38:51 +08:00
 andy12530
在nodejs中对同一个jade 文件register.jade进行:
res.render('register', {title: "注册新账户"});
或者
res.render('register', {title: "注册新账户", error: "error msg"});
操作。

如果error 存在的话,jade文件中会多输入一些html代码。
请问怎么写判断?
照文档中的判断语法写 if error 不行,提示error is not defined的错误。

那应该怎么写。
2985 次点击
所在节点    Node.js
6 条回复
NemoAlex
2013-03-27 22:44:20 +08:00
if error !== undefined
andy12530
2013-03-27 22:48:25 +08:00
@NemoAlex error is not defined ,之前已经试过了,不行的。。。依旧是那些错误
chshouyu
2013-03-27 22:50:06 +08:00
还是用ejs吧
andy12530
2013-03-27 22:53:45 +08:00
@chshouyu express内置默认jade,我就想试试呗。。。。貌似自己一直对模版很白痴,觉得模版用起来很不方便(第一次写的人可能会觉得很快),后期调试很麻烦。而且jade把html的兼容性全部给干掉了,一个字符都不能错。
NemoAlex
2013-03-27 22:54:12 +08:00
if typeof error !== 'undefined'
我脑残了,Sorry
duhastmich
2013-03-28 12:39:11 +08:00
@NemoAlex if locals.error

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/64242

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX