From f49b1006aa76ae2a32d351cb39674474ae96c81f Mon Sep 17 00:00:00 2001 From: Arnar Birgisson Date: Wed, 23 Jan 2013 22:25:34 +0100 Subject: [PATCH] Use tags correctly when set as a function. --- select2.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/select2.js b/select2.js index 0fa211e2..de29b2d6 100644 --- a/select2.js +++ b/select2.js @@ -397,17 +397,10 @@ the specific language governing permissions and limitations under the Apache Lic // TODO javadoc function tags(data) { - // TODO even for a function we should probably return a wrapper that does the same object/string check as - // the function for arrays. otherwise only functions that return objects are supported. - if ($.isFunction(data)) { - return data; - } - - // if not a function we assume it to be an array - + var isFunc = $.isFunction(data); return function (query) { var t = query.term, filtered = {results: []}; - $(data).each(function () { + $(isFunc ? data() : data).each(function () { var isObject = this.text !== undefined, text = isObject ? this.text : this; if (t === "" || query.matcher(t, text)) {