我整天都在寻找如何应用twitter bootstrap的typeahead插件而无法找到任何东西。现在,我如何在codeigniter中使用twitter bootstrap typeahead?
答案 0 :(得分: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此插件效果很好