Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在模板文件中使用从javascript获取表单字段错误数据_Javascript_Spring Mvc_Spring Boot_Thymeleaf - Fatal编程技术网

如何在模板文件中使用从javascript获取表单字段错误数据

如何在模板文件中使用从javascript获取表单字段错误数据,javascript,spring-mvc,spring-boot,thymeleaf,Javascript,Spring Mvc,Spring Boot,Thymeleaf,我在Spring引导应用程序中的thymeleaf模板中有一个表单。我可以在HTML(thymeleaf模板)中显示错误列表,如下所示: <ul> <li th:each="err : ${#fields.detailedErrors()}"> <b th:text="${err.getFieldName()}"></b> <span th:text="${err.getMessage()}"></span

我在Spring引导应用程序中的thymeleaf模板中有一个表单。我可以在HTML(thymeleaf模板)中显示错误列表,如下所示:

<ul>
    <li th:each="err : ${#fields.detailedErrors()}">
        <b th:text="${err.getFieldName()}"></b> <span th:text="${err.getMessage()}"></span>
    </li>
</ul>
内联javascript标记与上述HTML模板位于同一页面内,但后者不起作用。thymeleaf为javascript标记生成的HTML为:

<script>
    var fieldErrors = [];
</script>

var fieldErrors=[];
同时,为第一个div生成的HTML工作正常,如下所示:

<ul>
    <li><b>name</b> <span>may not be empty</span></li>
    <li><b>uri</b> <span>may not be empty</span></li>
</ul>
  • 名称不能为空
  • uri不能为空
简而言之,我的问题是,如何让
#fields.detailedErrors()
值在脚本标记中工作

<ul>
    <li><b>name</b> <span>may not be empty</span></li>
    <li><b>uri</b> <span>may not be empty</span></li>
</ul>