Javascript 引导:使用nextall()从typeahead创建2个dropdownlist

Javascript 引导:使用nextall()从typeahead创建2个dropdownlist,javascript,jquery,html,twitter-bootstrap,Javascript,Jquery,Html,Twitter Bootstrap,我从引导程序中获得了以下代码: 显然,它使用nextall()从typeahead创建了两种dropdownlist,但我不知道如何实现它。我是否需要更改引导typeahead文件中的某些内容 链接中的文本: 公开了typeahead呈现方法,因此您可以覆盖该方法,并根据从自定义源返回的对象类型自定义列表html。如果您想要生成新的twitter搜索/自动完成之类的东西,您需要这个。 将.next()更改为使用.nextAll(':has(a):first'),以便可以使用分离的结果类型。 范例

我从引导程序中获得了以下代码:

显然,它使用nextall()从typeahead创建了两种dropdownlist,但我不知道如何实现它。我是否需要更改引导typeahead文件中的某些内容

链接中的文本: 公开了typeahead呈现方法,因此您可以覆盖该方法,并根据从自定义源返回的对象类型自定义列表html。如果您想要生成新的twitter搜索/自动完成之类的东西,您需要这个。 将.next()更改为使用.nextAll(':has(a):first'),以便可以使用分离的结果类型。 范例


要实现您链接的提交(它似乎已经从引导源代码中消失),您可以下载并使用它,而不是原来的提交。
请注意,他的fork版本是2.0.4,如果您使用的是较新版本,则可能会导致问题

var labels
  , mapped
$("input").typeahead({
  source: function (query, process) {
    $.get('/autocomplete', { q: query }, function (data) {
      labels = []
      mapped = {}

      $.each(data, function (i, item) {
        mapped[item.label] = item.value
        labels.push(item.label)
      })

      process(labels)
    })
  },
  render: function () {
      var that = this

      items = $(mapped).map(function (i, item) {
        i = $(that.options.item).attr('data-value', item)

        if (item.thumb) { // Ok object has a thumbnail.
          i.find('a').append(''+that.highlighter(item));
        } else {
          i.find('a').html(that.highlighter(item))
        }

        return i[0]
      })

      items.first().addClass('active')
      this.$menu.html(items)
  },
  updater: function (item) {
    return mapped[item]
  }
})