Skip to content

Commit 476d5ac

Browse files
committed
recursive match in local()
1 parent d154146 commit 476d5ac

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

select2.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,29 @@
354354
}
355355

356356
return function (query) {
357-
var t = query.term, filtered = {};
357+
var t = query.term, filtered = { results: [] }, process;
358358
if (t === "") {
359359
query.callback({results: data});
360360
return;
361361
}
362-
filtered.results = $(data)
363-
.filter(function () {return query.matcher(t, text(this));})
364-
.get();
362+
363+
process = function(datum, collection) {
364+
var group;
365+
datum = datum[0];
366+
if (datum.children) {
367+
group = { text: text(datum), children: [] };
368+
$(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
369+
if (group.children.length) {
370+
collection.push(group);
371+
}
372+
} else {
373+
if (query.matcher(t, text(datum))) {
374+
collection.push(datum);
375+
}
376+
}
377+
};
378+
379+
$(data).each2(function(i, datum) { process(datum, filtered.results); });
365380
query.callback(filtered);
366381
};
367382
}

0 commit comments

Comments
 (0)