【发布时间】:2019-09-03 10:11:14
【问题描述】:
我有这个表遍历日志列表。我想做一个ajax调用,所以当单击特定行时,它会获取单击的日志的ID并获取该日志的特定详细信息/信息,并将信息插入到模式中。我需要两件事的帮助,一是因为它是一个动态 url,我在 url 中得到了 unicode 而不是实际的 id。我尝试在 log.id 周围添加 [[ ]],但这不起作用。我的第二个问题是我什至不确定我是否将日志 ID 发送到 ajax 调用。有人可以告诉我我是否走在正确的轨道上,或者如何摆脱 unicode 并转换 url 中的 id 吗?
<table class="table table-striped" data-toggle="table" data-show-toggle="true" data-classes="table-no-bordered" data-striped="true" data-search="true" data-show-columns="true" data-pagination="true">
<thead>
<tr>
<th>When</th>
<th>Subject</th>
<th>Notes</th>
<th class="text-right"><a class="btn btn-default"><span class="fa fa-pencil"></span></a></th>
<th class="text-right"><a class="trigger btn btn-default"><span class="fa fa-plus"></span></a></th>
</tr>
</thead>
<tbody>
<tr th:each="log : ${logs}">
<td th:if="${log.time!=null}" th:text="${{#temporals.format(log.time,'MM/dd/yyyy HH:mm a')}}"></td>
<td th:text="${log.subject}"></td>
<td style="white-space: pre-wrap;" th:text="${log.notes}"></td>
<td class="text-right"><a th:value="${log}" class="trigger-edit-log"><span class="fa fa-pencil"></span></a></td>
<td class="text-right"><a th:href="@{|/delete/callLog/${log.id}|}"><span class="fa fa-trash"></span></a></td>
</tr>
</tbody>
</table>
文档就绪函数内部的Ajax调用:
$(document).on('click', '.trigger-edit-log', function (event) {
event.preventDefault();
console.log($('a').attr('id'));
$.ajax({
url:"/callLogs/${{callLog.id}}",
data: "id="+ $('a').attr('id'),
success: function(data){
$('#editLog').append(data);
$('#editLog').html(data);
$('#modal-edit-log').iziModal('open');
}
});
});
@RequestMapping(value = "/callLog/{id}")
public String task(@PathVariable("id")CallLog callLog, Model model){
model.addAttribute("callLog",callLog);
return "redirect:/callLogs/client/" + callLog.getClient().getId();
}
【问题讨论】:
-
callLog.id是什么? -
不确定我是否应该使用 callLog,因为它是模型/类的正式名称,或者我是否应该使用 log.id,因为日志仅在 th:each 循环中形成...
标签: java ajax spring-boot thymeleaf