gpt4 book ai didi

java - Play框架: scala template, if语句问题

转载 作者:行者123 更新时间:2023-12-01 13:36:02 24 4
gpt4 key购买 nike

我不明白为什么这不起作用,这是我的模板代码:

@workuserForm: Form[WorkUser],queues: List[Queue])
@import helper._
@import helper.twitterBootstrap._

@main("User Form"){

@helper.form(action = routes.Users.saveWorkUser() , 'class -> "form-horizontal"){

@for(queue <- queues){
@repeat(workuserForm("queues"), min = 0){ wuQueue =>
@wuQueue("id").value
@queue.id
@if(wuQueue("id").value == queue.id){
checked
}
}
}

我得到的输出:

<小时/>

1 1

1 2

1 3

2 1

2 2

2 3

3 1

3 2

3 3

<小时/>

我应该去哪里:

<小时/>

1 1 已检查

1 2

1 3

2 1

2 2 已检查

2 3

3 1

3 2

3 3 已检查

<小时/>

我的模型:

public class WorkUser
{
public String showName;
public List<Queue> queues = new ArrayList<Queue>();
}


public class Queue extends Model
{
public long id;
public String name;
}

我的 Controller (我在其中调用 scala 模板)

public class Users extends Controller
{
private static final Form<WorkUser> workuserForm = Form.form(WorkUser.class);
public static Result newWorkUser()
{
List<Queue> queues = Queue.findAll();
WorkUser workUserAux = new WorkUser();
workUserAux.queues = queues;
Form<WorkUser> filledForm = workuserForm.fill(workUserAux);
return ok(views.html.workUser.render(filledForm,queues));
}
}

看来问题出在if语句上,但我无法解决,我已经尝试了所有。

最佳答案

wuQueue("id").value 的类型为 Stringqueue.id 的类型为 Long >,所以你的平等检查永远不会通过。考虑将其重写为:

@if(wuQueue("id").value.toLong == queue.id){
checked
}

关于java - Play框架: scala template, if语句问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21266826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com