我有一个表单对象,我需要检查一个字段的值是否等于某个字符串
我正在尝试这个,但它不起作用
@if(sp.pageType.equals("customreCare")) {
//render this specific div
} else {
//render this other div
}
但不幸的是它不起作用,它的语法是什么?
最佳答案
使用 ==
比较字符串的运算符:
@defining("something") {whatToTest =>
@if(whatToTest == "something"){ There is something } else { There is.... nothing }
}
所以在你的情况下(当然要确保像
customreCare
...)这样的条件没有拼写错误:@if(sp.pageType == "customreCare") {
//render this specific div
} else {
//render this other div
}
关于templates - Play 2 : How to compare strings in scala template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12697969/