spring - Thymeleaf 上的自动完成数据列表
问题描述
我正在使用 Thymeleaf 模板构建一个视图,其中包含一个表单,该表单提供了一种将我的输入值与模型中传递的属性绑定的方法。后端是使用 Spring 4 开发的。
以下代码段包含一个自动完成数据列表,其中包含名称列表对象的数据,该数据列表作为属性添加到模型中。所述名称列表是具有字段int id
和的类的 ArrayList String name
。
<form th:action="@{/}" method="POST" th:object="${example}">
<div class="form-group">
<input list="names" class="form-control" id="nameinput" th:field="${example.num.id}"> </input>
<datalist id="names">
<option th:each="row : ${namelist}" th:value="${row.id}" th:label="${row.name}">
</datalist>
<button>submit</button>
</div>
</form>
所选选项的值已经绑定到 example.num.id,这是预期和期望的行为。但是,当在 Web 浏览器上加载视图时(在最新的 Firefox 和 Chrome 上测试),它是这样表示的:
如您所见,id 正在显示。但是,我正在尝试模仿 ; 的行为<select>
。该值不应显示,仅显示文本或标签。
有没有更好的方法来实现这一目标?我没有正确使用数据列表吗?
解决方案
推荐阅读
- linux - Linux 中 mv 命令的使用
- php - 使用 SSL+AUTH 发送 PHP PEAR 邮件失败
- vue.js - 具有命名空间模块和未知突变类型的 Vuejs
- swift - 解析格式为 yyyy-MM-dd'T'HH:mm:ss'Z' 的 rfc 3339 日期字符串返回 nil
- firebase - 我应该直接查询我的 Firebase 数据库,还是使用 Cloud Functions?
- r - Dplyr 管道操作获得最小值
- python-3.x - Python Selenium 没有点击按钮
- python - Python跨平台清屏问题
- python - 如何遍历数组的一部分,为什么我的循环不起作用?
- python - 将python转换为kivy语言