如何将Play Framework 2表单中的枚举与枚举值进行比较?即使它们是平等的,这个陈述也会失败。
@if(myForm("sectionType").value == SectionType.MAIN_CONTACT_INFO) {
}
答案 0 :(得分:3)
您已经说myForm("sectionType").value
是Option[String]
,因此您无法直接使用toString
,因为Some("hello").toString
会返回“Some(hello)”。
我建议尝试使用这种语法:
myForm("sectionType").value.get == SectionType.MAIN_CONTACT_INFO.toString
// or .getOrElse("") to avoid errors
如果有必要,请不要忘记导入SectionType
(即如果此类不在模型包中)