我有这个 scala 模板,并希望使用 case 语句根据匹配的枚举值呈现不同的 html。
我的模板如下所示:
@(tagStatus: String)
try {
TagStatus.withName(tagStatus) match {
case TagStatus.deployed => {<span class="label label-success">@tagStatus</span>}
case TagStatus.deployedPartially => {<span class="label label-important">@tagStatus</span>}
case TagStatus.deployedWithProblems => {<span class="label label-important">@tagStatus</span>}
}
} catch {
{<span class="label label-important">??</span>}
}
枚举看起来像这样:
object TagStatus extends Enumeration{
val deployed = Value("deployed")
val deployedWithProblems = Value("deployed_with_problems")
val deployedPartially = Value("deployed_partially")
}
当我运行它时,我得到:
Compilation error
')' expected but 'case' found.
In C:\...\statusTag.scala.html at line 8.
5 case TagStatus.deployed => {<span class="label label-success">@tagStatus</span>}
6 case TagStatus.deployedPartially => {<span class="label label-important">@tagStatus</span>}
7 case TagStatus.deployedWithProblems => {<span class="label label-important">@tagStatus</span>}
8 }
9 } catch {
10 {<span class="label label-important">??</span>}
11 }
我不知道这个错误消息是什么意思。
为了编译这个简单的代码片段,我缺少什么?
谢谢!