0

我整天都在寻找如何应用 twitter bootstrap 的 typeahead 插件但找不到任何东西。现在,如何在 codeigniter 中使用 twitter bootstrap typeahead?

4

1 回答 1

2

您可以使用BS Typeahead fork,它支持 ajax 调用。

# This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
      # this function receives the typeahead object and the query string
      $.ajax(
        url: "/lookup/?q="+query
        # i'm binding the function here using CoffeeScript syntactic sugar,
        # you can use for example Underscore's bind function instead.
        success: (data) =>
          # data must be a list of either strings or objects
          # data = [{'name': 'Joe', }, {'name': 'Henry'}, ...]
          typeahead.process(data)
      )
    # if we return objects to typeahead.process we must specify the property
    # that typeahead uses to look up the display value
    property: "name"
  )

例如 :-

$('.typeahead').typeahead({
    source: function (query, process) {
        return $.get('/typeahead', { query: query }, function (data) {
            return process(data.options);
        });
    }
});

或者你可以使用:- Ajax-Typeahead这个插件运行良好

于 2012-10-03T13:47:07.177 回答