我正在尝试在 Play 中使用“选择”表单元素! 2.3,无法让它工作。我需要向模板提供什么?目前我有这个:
public static Result add(Long sensorId) {
Form<Action> myForm = Form.form(Action.class);
Sensor sensor = Sensor.find.byId(sensorId);
Action action = new Action();
action.actionUp = true;
action.sensor = sensor;
myForm.fill(action);
HashMap<String, String> devices = new HashMap<>();
for(Device device : Device.find.all()){
devices.put(device.id.toString(), device.name);
}
return ok(editView.render(myForm, action, devices));
}
模板:
@(myForm: Form[models.Action], action: models.Action, deviceList: HashMap[String, String])
@helper.select(myForm("device"), deviceList,'_label -> "Perform on device")
但这不起作用,因为它需要 Seq[(String, String)]。 但我找不到用 Java 创建它的方法...非常感谢任何帮助!
最佳答案
表单助手不会知道,如果您直接将 deviceList
放入 select
中,最后它会期望您提供 options
。这就是原因,它显示此错误需要 Seq[(String, String)]
。
要解决此问题,您必须通过 options
包装 deviceList
,让助手知道 deviceList
是 select
的 options
。
所以应该像下面这样。
@helper.select(myForm("device"), options(deviceList),'_label -> "Perform on device")
关于java - 在 Play 中使用@select! Framework 2.3模板和Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28303823/