【问题标题】:Handle selected event with bootstrap Typeahead使用引导程序 Typeahead 处理选定的事件
【发布时间】:2017-05-16 10:51:55
【问题描述】:

我正在尝试使用 bootstrap typeahead。 我在处理已选择的项目时遇到问题。

下面是我的代码

  var bindto = $(".search.typeahead");
        bindto.typeahead({
            source: function (query, response) {
                var map = {};
                var advicesearchList = [];
                return $.ajax({
                    url: "/Advice/AutoComplete",
                    type: "GET",
                    cache: false,
                    data: { querystring: query },
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $.each(data, function (i, result) {
                            map[result.Title] = result;
                            advicesearchList.push(result.Title);
                        });
                        response(advicesearchList);
                    }
                });
            }
        }).on("typeahead:selected", function (e, o) {
            console.log("item selected");

        });

检测用户从列表中的一项中选择的内容的正确方法是什么

谢谢

【问题讨论】:

    标签: javascript typeahead bootstrap-typeahead


    【解决方案1】:

    尝试使用 afterSelected 选项:

        var bindto = $(".search.typeahead");
        bindto.typeahead({
        source: function (query, response) {
            //your code...
        }, afterSelect: function (data) {
            //print the data to developer tool's console
            console.log(data);
            }
        });
    

    Docs

    【讨论】:

      猜你喜欢
      • 2012-03-21
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 2013-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多