是否可以检查二维数组中是否存在特定元素?
<div th:each="employee, i : ${company.employees}">
<div th:each="duty, j : ${employee.duties}">
<div class="custom-control custom-checkbox my-1 mr-sm-2">
<input type="checkbox" name="duties"
th:id="${j.index}" th:value="${j.index}"
th:checked="${#arrays.contains(${company.tasks[i.index][]}, ${duty.id})}" />
<label th:for="${j.index}" th:text="${j.index}"></label>
</div>
</div>
</div>
Java 等效项应该是:
for (int i=0; i<company.getEmployees().length; i++)
for (Duty duty : company.getEmployees().[i].getDuties())
boolean checked = company.getTasks()[i].contains(duty.id);
// Contains, method that checks whether element exists on array
冉冉说
相关分类