V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
andy12530
V2EX  ›  Node.js

问一个关于jade的问题

  •  
  •   andy12530 · 2013-03-27 22:38:51 +08:00 · 2947 次点击
    这是一个创建于 4041 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在nodejs中对同一个jade 文件register.jade进行:
    res.render('register', {title: "注册新账户"});
    或者
    res.render('register', {title: "注册新账户", error: "error msg"});
    操作。

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

    那应该怎么写。
    6 条回复    1970-01-01 08:00:00 +08:00
    NemoAlex
        1
    NemoAlex  
       2013-03-27 22:44:20 +08:00 via iPad   ❤️ 1
    if error !== undefined
    andy12530
        2
    andy12530  
    OP
       2013-03-27 22:48:25 +08:00
    @NemoAlex error is not defined ,之前已经试过了,不行的。。。依旧是那些错误
    chshouyu
        3
    chshouyu  
       2013-03-27 22:50:06 +08:00
    还是用ejs吧
    andy12530
        4
    andy12530  
    OP
       2013-03-27 22:53:45 +08:00
    @chshouyu express内置默认jade,我就想试试呗。。。。貌似自己一直对模版很白痴,觉得模版用起来很不方便(第一次写的人可能会觉得很快),后期调试很麻烦。而且jade把html的兼容性全部给干掉了,一个字符都不能错。
    NemoAlex
        5
    NemoAlex  
       2013-03-27 22:54:12 +08:00 via iPad
    if typeof error !== 'undefined'
    我脑残了,Sorry
    duhastmich
        6
    duhastmich  
       2013-03-28 12:39:11 +08:00
    @NemoAlex if locals.error
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   901 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:05 · PVG 06:05 · LAX 15:05 · JFK 18:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.