从表格中获取一个项目,然后在SpringBoot / Thymeleaf

时间:2019-04-12 00:08:10

标签: java spring-boot thymeleaf

我有一个贯穿所有日志的表,并将每个日志及其相关详细信息放在一行中。我想单击一行,弹出带有该行的日志信息的模式信息,以便我可以对其进行编辑。我不确定如何在SpringBoot中获取该特定日志以将其插入表单中的th:object =“ $ {}”中,因为我无法将一个日志的对象放入控制器函数中,因为我不知道会有人点击。我该如何根据他们单击的表行来获取ID /日志信息,以填充模式?

最好的方法是使用javascript吗?还是我需要在控制器中添加某种逻辑?

这是桌子:

                        <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>

这是打开模式的Java语言。我试图将单击的行设置为变量callLog,并将其插入到模式的th:object中,但这没用:

            $(document).on('click', '.trigger-edit-log', function (event) {
                event.preventDefault();
                var callLog = $(this);
                $('#modal-edit-log').iziModal('open');
            });

这是模态

                <div id="modal-edit-log" data-izimodal-title="Edit Log" class="modal">
                    <form th:action="@{/save/log}" th:object=??? method="post" style="padding:0 10px;">
                        <br/>
                        <!--<input type="hidden" th:field="*{id}"/>-->
                        <!--<input type="hidden" th:value="*{client.id}" th:name="client" th:id="client"/>-->
                        <div class="row">
                            <div class="col-xs-4 col-sm-3 text-right"><label>Subject:</label></div>
                            <div class="col-xs-8 col-sm-7"><input type="text" class="form-control" th:field="*{subject}"/> </div>
                        </div>
                        <br/>
                        <div class="row">
                            <div class="col-xs-4 col-sm-3 text-right"><label>Notes:</label></div>
                            <div class="col-xs-8 col-sm-7"><input type="text" class="form-control" th:field="*{notes}"/> </div>
                        </div>
                        <br/>
                        <div class="text-right">
                            <input type="submit" value="Submit" class="btn btn-default"/>
                        </div>
                        <br/>
                    </form>
                </div>

我的控制器,如果需要查看的话:

    @RequestMapping(value="/callLogs/client/{id}")
    public String getCallLogs(Model model, @PathVariable("id") Long id){
        Client client=clientRepository.findById(id);
        CallLog newCallLog=new CallLog();
        List<CallLog> logs=callLogRepository.findByClientOrderByTimeDesc(client);
        List<Role> assignees= roleRepository.findByIsTaskAssignee(true);
        List<Task> tasks=taskRepository.findByClient(client);

        model.addAttribute("assignees",assignees);
        model.addAttribute("newTask",new Task());
        model.addAttribute("tasks",tasks);
        model.addAttribute("client",client);
        model.addAttribute("logs",logs);
        model.addAttribute("newCallLog",newCallLog);
        return ("callLogs");
    }

0 个答案:

没有答案