【发布时间】:2021-12-31 15:58:04
【问题描述】:
我在网上搜索我无法弄清楚是否有机会从列表中的静态 html 中为变量赋值。
<#list users as user>
<#assign userId = //the user id value here// ><p>${user.id} </p>
</#list>
用户id值必须来自<p>标签
编辑
<tbody>
<#assign count = 1>
<#list departmentsList as department>
<tr>
<td>${count}</td>
<td>${department.name}</td>
<td class="text-right">
<div class="dropdown dropdown-action">
<a href="#" class="action-icon dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><i class="material-icons">more_vert</i></a>
<div class="dropdown-menu dropdown-menu-right">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#edit_department"><i class="fa fa-pencil m-r-5"></i>Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#delete_department"><i class="fa fa-trash-o m-r-5"></i> Delete</a>
<#assign employeeId = ${employee.id}>
</div>
</div>
</td>
</tr>
<#assign count ++>
</#list>
</tbody>
${employeeId} 从列表中返回最后一个元素。我需要选择。
这是我使用的表格我做一个循环表单列表我需要单击锚点来获取当前部门 ID 我尝试使用 href,但它不起作用,因为 data-target="#edit_department 使用 JavaScript 并且不起作用。当按下 EDIT 或 DELETE 以使用 HTML 中的变量时,如何获取所选部门的 ID,该变量在按下锚点后打开并位于另一个 div 中
带有操作表单的 HTML DIV
<div id="edit_department" class="modal custom-modal fade" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Department</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="departments/update/${departmentId}" method="post">
<div class="form-group">
<label>Department Name <span class="text-danger">*</span></label>
<input name="name" class="form-control" type="text">
</div>
<div class="submit-section">
<button class="btn btn-primary submit-btn">Save</button>
</div>
</form>
</div>
</div>
</div>
【问题讨论】:
-
您的表格可以有许多部门,每个部门都有自己的 id,但您的 JavaScript 代码只能打开一个
<div id="edit_department">。因此,您的 JavaScript 代码必须读出需要编辑的部门 id 并插入到<div id="edit_department">内的表单中(并且为了进行编辑,您可能还希望将当前部门名称设置为默认名称)。跨度> -
与问题无关,但请注意,您不需要维护自己的
count变量。相反,您可以使用<td>${department?counter}</td>。 -
是的,我在发布问题时对此并不熟悉。谢谢。
标签: java html spring templates freemarker