Merge pull request #341 from ryfeng/master
Recursive Match for local query
This commit is contained in:
commit
045bff7fe4
23
select2.js
23
select2.js
@ -354,14 +354,29 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return function (query) {
|
return function (query) {
|
||||||
var t = query.term, filtered = {};
|
var t = query.term, filtered = { results: [] }, process;
|
||||||
if (t === "") {
|
if (t === "") {
|
||||||
query.callback({results: data});
|
query.callback({results: data});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
filtered.results = $(data)
|
|
||||||
.filter(function () {return query.matcher(t, text(this));})
|
process = function(datum, collection) {
|
||||||
.get();
|
var group;
|
||||||
|
datum = datum[0];
|
||||||
|
if (datum.children) {
|
||||||
|
group = { text: text(datum), children: [] };
|
||||||
|
$(datum.children).each2(function(i, childDatum) { process(childDatum, group.children); });
|
||||||
|
if (group.children.length) {
|
||||||
|
collection.push(group);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (query.matcher(t, text(datum))) {
|
||||||
|
collection.push(datum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$(data).each2(function(i, datum) { process(datum, filtered.results); });
|
||||||
query.callback(filtered);
|
query.callback(filtered);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user