jquery - 在百里香中创建一个简单的自动完成文本框
问题描述
我是 SpringBoot 和 thymeleaf 的新手,我正在尝试完成一个自动完成文本框,该文本框提供医生姓名作为建议。但它没有按预期工作,也没有显示任何建议。我尝试了几种方法并走了通过几个教程。
这是我的html代码
<label>Doctor Name:</label>
<input type="text" class="form-control" th:field="*{name}" id="doctor_name">
这是我的相关 Jquery
<script type="text/javascript">
$(function() {
$("#doctor_name").autocomplete({
source: "nameAutoComplete",
minLength: 3
});
});
</script>
这是我在控制器类中的处理程序方法
@RequestMapping(value = "/nameAutoComplete")
public List<String> nameAutoComplete(@RequestParam(value = "term",required=false,defaultValue = "")String term){
List<String> suggestions=new ArrayList<String>();
suggestions.add("Andrew Bayes");
suggestions.add("Asher");
suggestions.add("Anthony");
return suggestions;
}
}
我还根据教程包含了以下链接
<script th:src="@{https://code.jquery.com/jquery-1.12.4.js}"></script>
<script th:src="@{https://code.jquery.com/ui/1.12.1/jquery-ui.js}"></script>
请提出一些建议来纠正我的方法。
解决方案
推荐阅读
- awk - 基于公共键在awk中合并3个文件
- python - 如何使用 pandas 读取并推送到 SQL 数据库中的文件不断获取数据
- python - Beautiful Soup - 在没有嵌套跨度的情况下获得顶部 div 标签
- json - 如何使用 vbscript 从 JSON 文件中获取值到变量中
- sql - LEFT JOIN 不会返回所有值
- java - Apache commons CSV 忽略 csv 文件中损坏或无效的记录并继续解析
- python - Django重定向,反向
- reactjs - 在向/从 github 存储库推送、拉取或合并代码时,我是否需要停止我的 localhost 服务器?
- c++ - 如何将双精度转换为字符串的总位数(小数点的左侧和右侧)?
- java - 为什么我不能在消费者工厂中设置反序列化器?