该代码显示一个列表中的对象,但不显示另一个列表中的对象

时间:2019-08-31 06:29:24

标签: html thymeleaf

我希望“选择”列出除已记录的学生以外的所有学生,但“学生”列表似乎为空。

<ul type="none" th:each="discipline : ${disciplineList.disciplines}">
            <li><b th:onclick="|javascript:showDiv('${discipline.id}');|"
                   th:text="${discipline.name}"
                   class="discipline-name" style="cursor: pointer;"></b>
                <div th:id="${discipline.id}" style="display: none;">
                    <ul th:name="${discipline.name}" class="discipline-info"
                        th:unless="${#lists.isEmpty(discipline.students)}">
                        <li th:each="student : ${discipline.students}"
                            th:text="${student.student}" class="studName"></li>
                    </ul>
                    <div class="studOption" >
                        <select class="selStud" required >
                            <option th:each="student : ${students}"
                                    th:value="${student.id}"
                                    th:text="${student.student}">Select</option>
                        </select>
                        <input type="submit" class="add-student-to-disc" value="Добавить в дисциплину">
                    </div>
                </div>
            </li>
        </ul>

现在页面的源代码如下:

<ul type="none">
            <li><b onclick="javascript:showDiv(&#39;7&#39;);"
                   class="discipline-name" style="cursor: pointer;">tyu</b>
                <div id="7" style="display: none;">
                    <ul name="tyu" class="discipline-info">
                        <li class="studName">hjk</li>
                    </ul>
                    <div class="studOption" >
                        <select class="selStud" required >

                        </select>
                        <input type="submit" class="add-student-to-disc" value="Добавить в дисциплину">
                    </div>
                </div>
            </li>
        </ul>

另一个html上的相同构造将显示所有学生:

<div th:each="student: ${students}" class="student">
            <form class="student-form" method="post">
                <div th:text="${student.student}" class="student-name"></div>
                <input required th:attr="value=${student.student}" class="student-name-input" name="studentName">
                <input type="submit" class="btn add-student-btn remove-student-btn" value="Удалить">
            </form>
        </div>

如果我复制上面的代码并放在ul标记之前或之后,它也不会给我任何东西。

1 个答案:

答案 0 :(得分:0)

一切都很简单。我尚未添加到控制器中

modelAndView.addObject(students, ...);