玉调节给var一个默认值

时间:2015-10-23 06:03:40

标签: javascript node.js pug

我可以这样做吗

NULL

在玉?

如果something else为空,如何显示myVarIn XML file add Button <Button android:id="@+id/btn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/mText" android:layout_gravity="center" android:gravity="center"/> and in Strings.xml add <string name="mText">TEXT In CAPITAL LETTERS\n(TEXT IN SMALL LETTERS)</string> ?我试过上面的片段,它根本没有显示任何内容。

3 个答案:

答案 0 :(得分:1)

在Jade中,您可以像使用javascript一样使用条件语句。

http://jade-lang.com/reference/conditionals/

如果它评估为falsy:

- if (myVar)
    h1=myVar
- else
    h1 Null

答案 1 :(得分:1)

使用领先的宣传声明变量

-myVar = null
h1= "h1= '" + myVar + "' with myVar: '" + myVar + "'"
// displays: h1= 'null' with myVar: 'null'

-myVar = 'Hello lucky boy'
h1= "h1= '" + myVar + "' with myVar: '" + myVar + "'"
// displays: h1= 'Hello lucky boy' with myVar: 'Hello lucky boy'

-anotherVar = (myVar || null)
h1= "h1= '" + anotherVar + "' with myVar: '-anotherVar = (myVar || null)'"
// h1= 'Hello lucky boy' with myVar: '-anotherVar = (myVar || null)'

-myVar = null
if myVar
  h1= 'myVar has content'
else
  h1= 'something else'
// displays: something else

您可以通过在“test.jade”文件中保存内容,运行jade test.jade然后在浏览器中查看test.html来尝试这些小测试。

这个网站有一些很好的例子和一个互动游乐场:https://naltatis.github.io/jade-syntax-docs/

玩得开心。

答案 2 :(得分:0)

如果NULL是一个字符串,则需要将其括在引号中:

#{myVar || "NULL"}

同样,您可以将其替换为任何其他字符串

#{myVar || "something else"}