andy12530
V2EX  ›  Node.js

问一个关于jade的问题

  •  
  •   andy12530 · Mar 27, 2013 · 3711 views
    This topic created in 4807 days ago, the information mentioned may be changed or developed.
    在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 replies    1970-01-01 08:00:00 +08:00
    NemoAlex
        1
    NemoAlex  
       Mar 27, 2013 via iPad   ❤️ 1
    if error !== undefined
    andy12530
        2
    andy12530  
    OP
       Mar 27, 2013
    @NemoAlex error is not defined ,之前已经试过了,不行的。。。依旧是那些错误
    chshouyu
        3
    chshouyu  
       Mar 27, 2013
    还是用ejs吧
    andy12530
        4
    andy12530  
    OP
       Mar 27, 2013
    @chshouyu express内置默认jade,我就想试试呗。。。。貌似自己一直对模版很白痴,觉得模版用起来很不方便(第一次写的人可能会觉得很快),后期调试很麻烦。而且jade把html的兼容性全部给干掉了,一个字符都不能错。
    NemoAlex
        5
    NemoAlex  
       Mar 27, 2013 via iPad
    if typeof error !== 'undefined'
    我脑残了,Sorry
    duhastmich
        6
    duhastmich  
       Mar 28, 2013
    @NemoAlex if locals.error
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5942 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 466ea39e · 46ms · UTC 03:32 · PVG 11:32 · LAX 20:32 · JFK 23:32
    ♥ Do have faith in what you're doing.