2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-05 16:42:29 +03:00

Alter typeahead to accept synchronous/asynchronous data source via function/callback

This commit is contained in:
Matt Morgan
2012-04-26 14:09:20 -04:00
parent b261f9781b
commit bf9d8fcc07
3 changed files with 50 additions and 8 deletions
+11 -5
View File
@@ -77,9 +77,7 @@
}
, lookup: function (event) {
var that = this
, items
, q
var items
this.query = this.$element.val()
@@ -87,7 +85,15 @@
return this.shown ? this.hide() : this
}
items = $.grep(this.source, function (item) {
items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source
return items ? this.process(items) : this
}
, process: function (items) {
var that = this
items = $.grep(items, function (item) {
return that.matcher(item)
})
@@ -282,4 +288,4 @@
})
})
}(window.jQuery);
}(window.jQuery);