2

I can't find any documentation of what "when" means in scala template. I've seen it on multiple places like scala samples - forms application. What is the meaning of when, what it's suppose to do when it's true and respectively when it's false? Are there any restriction for this construct? Is there a place where I can see the description of this and others scala template constructs?

Sample code snippet:

<li class="@("active".when(nav == "signup"))">

Thank you

4

1 回答 1

2

可以看到 when 2.0.4 / 2.1.0的定义。

它是 RichString 的成员,它按名称接受一个布尔谓词。String 被隐式转换为 RichString。

这意味着您只能在字符串上使用 when,并且您必须将其传递给布尔类型的参数。

谓词为真时返回字符串,假时返回空字符串。

于 2012-12-02T20:26:03.087 回答