我有一门课程,上面有一份参与者名单。
public class course {
private List<Address> attendeeList;
public List<Address> getAttendeeList() {
return attendeeList;
}
}
如果我编辑现有课程,我希望选择字段自动选择正确参与者的选项。下面是我的html页面的摘录:
<p class="form-control-static" th:each="i, stat : ${course.attendeeList}">
<select class="form-control" name="attendeeIds">
<option th:value="0">Please select an Attendee</option>
<option th:each="attendee : ${addresses}"
th:value="${attendee.id}"
th:text="${attendee.firstName}+' '+${attendee.lastName}"
th:selected="${attendee.id}==
(course.attendeeList[${stat.index}].id})">
</option>
</select>
</p>
如果我打开页面,我得到以下错误:意外令牌。应为“rsquare(])”,但应为“lcurly({)”
如果我将${stat.index}替换为数字(例如0),并且我的课程有10名参与者,则选择的项目将出现10次,但始终选择第一个成员。如何在每个选择字段中选择正确的与会者?
发布于 2018-06-06 08:59:31
尝试从以下位置更改:
(course.attendeeList[${stat.index}].id})">
至:
(course.attendeeList[__${stat.index}__].id})">
发布于 2018-06-06 10:30:34
当您在表达式中时,您不需要使用另一个${...}
。我会把这个表达式写成:
th:selected="${attendee.id == course.attendeeList[stat.index].id}"
https://stackoverflow.com/questions/50710740
复制相似问题