是node.js的新功能。我已经使用express生成了一个简单的网站。我在中添加了以下文本index.jade
:
raining = true
if(raining === true)
p It is raining. Take an umbrella!
else
p No rain. Take the bike!
当我注释掉最后两个语句时,得到了预期的响应:“正在下雨。请撑伞!”
当我包含最后两行时,出现意外的令牌错误:
Unexpected token (57:0)
SyntaxError: Unexpected token (57:0)
at Parser.pp.raise (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:943:13)
at Parser.pp.unexpected (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:1503:8)
at Parser.pp.parseExprAtom (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:327:12)
at Parser.pp.parseExprSubscripts (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:216:19)
at Parser.pp.parseMaybeUnary (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:197:19)
at Parser.pp.parseExprOps (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:151:19)
at Parser.pp.parseMaybeConditional (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:133:19)
at Parser.pp.parseMaybeAssign (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:110:19)
at Parser.pp.parseExpression (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:86:19)
at Parser.pp.parseStatement (/home/ubuntu/workspace/node_modules/jade/node_modules/with/node_modules/acorn-globals/node_modules/acorn/dist/acorn.js:1750:23)
不知道为什么包含else语句会导致错误。任何建议将不胜感激。
注意缩进:
这是一个例子
http://jsfiddle.net/heanfig/z8wn5qz9/
查玉参考
http://learnjade.com/tour/conditionals/
- var raining = true
if raining == true
p It is raining. Take an umbrella!
else
p No rain. Take the bike!
甚至:
| #{raining ? raining : 'man'}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句