【发布时间】:2023-03-12 16:16:01
【问题描述】:
当我打开一个新表单时,所有的 js 都可以工作,在编辑时它无法加载所有的内部 js。请在所有数据和路由都正确连接的假设下工作。
我有一个链接可以打开一个包含现有对象的表单:
<a th:if="${foo.typeName} == a" href="Edit"
th:href="@{/aFoo/{id}(id=${foo.id})}">view</a>
控制器方法:
新对象:
@RequestMapping(value="/aFoo", method=RequestMethod.GET)
public String newAFooForm(Model model) {
FooViewModel fooViewModel = new FooViewModel(Type.A);
model.addAttribute("fooViewModel", fooViewModel);
return "fooForm";
}
加载现有对象:
@RequestMapping(value="/aFoo/{id}", method=RequestMethod.GET)
public String editAFooForm(@PathVariable("id") Long id, Model model) {
FooViewModel fooViewModel = assignFooViewModel(id);
model.addAttribute("fooViewModel", fooViewModel);
return "fooForm";
}
表单 html/th 代码无关紧要,但要描述我的 js 引用:
layout.html 是两种表单的容器。它有 js 导入:
<script th:src="@{js/jquery-1.11.3.min.js}"></script>
<script th:src="@{js/bootstrap.min.js}"></script>
<script th:src="@{js/parsley.min.js}"></script>
以及包含页面上的 js 模板:
<div layout:fragment="script"></div>
fooForm.html 有额外的 js 导入,然后是大量的 js 代码,它开始了:
<div layout:fragment="script">
<script th:src="@{js/typeahead.bundle.min.js}"></script>
<script th:src="@{js/handlebars.js}"></script>
<script>
....
</script>
</div>
我的第一个想法是我以某种方式编写了错误的链接,因此它丢失了引用 js 的上下文。有什么想法吗?谢谢。
【问题讨论】:
-
发布为 script 标签生成的 HTML 代码。
标签: javascript spring-boot thymeleaf