【问题标题】:matcher function typeahead匹配器函数预先输入
【发布时间】:2023-03-27 02:12:01
【问题描述】:

我正在尝试使用 typeahead 的匹配器功能来检查我的搜索是否没有返回任何结果。如果它没有返回任何结果,我想在搜索栏的末尾附加一个 div。但是,匹配器功能导致我的荧光笔中断并返回随机结果。有谁知道是否有办法在不使用 matcher 函数的情况下完成此任务,或者在这种情况下如何正确使用它?我想我可能采取了错误的方法。

$('.shop_search').typeahead({
        source: function (query, process) {
            map = {};
            $.each(data, function (i, data) {
                map[data.text] = {
                    address: data.text2,
                    name: data.text,
                    post: data.post
                };
                shops.push(data.text);
            });
            process(shops);
            shops = [];
        },

        minLength: 3,
        matcher: function (item) {
            if (item.indexOf(this.query) == -1) {
                $(".dropdown-menu").append($('<li><button class="btn" >Advanced                                                   Search</button></li>'));
                return true;
            }
        },

        highlighter: function (item) {
            var p = map[item];
            var itm = ''
                     + "<div class='typeahead_primary'>" + p.name + "</div>"
                     + "<div class='typeahead_secondary'>" + p.address +  </div>"
                     + "</div>"
                     + "</div>";
            return itm;
        },
     });

【问题讨论】:

    标签: javascript jquery search typeahead.js


    【解决方案1】:

    在我看来你忘记了一个“

    + "<div class='typeahead_secondary'>" + p.address +  </div>"
    

    应该是

    + "<div class='typeahead_secondary'>" + p.address +  "</div>"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多