首页 > 解决方案 > 在百里香中创建一个简单的自动完成文本框

问题描述

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

请提出一些建议来纠正我的方法。

标签: jqueryspring-bootthymeleaf

解决方案


推荐阅读