类别自动完成jQuery中的单词级自定义筛选器,而不是子字符串

Custom filter at word level, not substring, in category autocomplete jQuery

本文关键字:筛选 字符串 自定义 单词级 jQuery      更新时间:2023-09-26

我在自动完成中填充了数千个数据。如果键入一个字母,比如a,则会显示所有带有字符a的标签,但我需要包含单个单词a或以字符a开头的结果。

帮个忙???

最后我用json 完成了

$("#search")
                .catcomplete(
                        {
                            delay : 0,
                            source :function(request, response) {
                                $.ajax({
                                    url: '<c:url value="/JSON/getDataAU.jspx"/>',
                                    dataType: "json",
                                    data:request,
                                    success: function( data, textStatus, jqXHR) {
                                        console.log( data);
                                        var items = data;
                                        response(items);
                                    },
                                    error: function(jqXHR, textStatus, errorThrown){
                                         console.log(errorThrown);
                                    }
                                });
                            },
                            select : function(event, ui) {
                                $('#form1')
                                        .append(
                                                '<input type="hidden" name="searchIndex" value="'+ui.item.idd+'" />');
                                $('#form1')
                                        .append(
                                                '<input type="hidden" name="searchCity" value="'+ui.item.label+'" />');
                            }
                        });

和控制器

@RequestMapping(value="/getDataAU", method=RequestMethod.GET)
public void populateAutocomplete(HttpServletRequest request, HttpServletResponse  response,@RequestParam("term")String term){
    response.setContentType("application/json");
    Gson gson = new Gson();
    JSONObject obj = new JSONObject();
    try{
        obj.put("label","Nepal");
        obj.put("category", "country");
        obj.put("idd", "2");
    }catch(Exception e){e.printStackTrace();    }
    String send = gson.toJson(obj);
    System.out.println(send);
    try {
        response.getWriter().write(send);
    } catch (IOException e) {
        e.printStackTrace();
    }
}