Fixing when the data helper is a function for the local query
Signed-off-by: Igor Vaynberg <igor.vaynberg@gmail.com>
This commit is contained in:
parent
7d908da52f
commit
6278e7cca0
21
select2.js
21
select2.js
@ -406,15 +406,6 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
tmp,
|
tmp,
|
||||||
text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
|
text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
|
||||||
|
|
||||||
if (!$.isArray(data)) {
|
|
||||||
text = data.text;
|
|
||||||
// if text is not a function we assume it to be a key name
|
|
||||||
if (!$.isFunction(text)) {
|
|
||||||
dataText = data.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
|
|
||||||
text = function (item) { return item[dataText]; };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($.isArray(data)) {
|
if ($.isArray(data)) {
|
||||||
tmp = data;
|
tmp = data;
|
||||||
data = { results: tmp };
|
data = { results: tmp };
|
||||||
@ -425,6 +416,16 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
data = function() { return tmp; };
|
data = function() { return tmp; };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dataItem = data();
|
||||||
|
if (dataItem.text) {
|
||||||
|
text = dataItem.text;
|
||||||
|
// if text is not a function we assume it to be a key name
|
||||||
|
if (!$.isFunction(text)) {
|
||||||
|
dataText = data.text; // we need to store this in a separate variable because in the next step data gets reset and data.text is no longer available
|
||||||
|
text = function (item) { return item[dataText]; };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return function (query) {
|
return function (query) {
|
||||||
var t = query.term, filtered = { results: [] }, process;
|
var t = query.term, filtered = { results: [] }, process;
|
||||||
if (t === "") {
|
if (t === "") {
|
||||||
@ -452,7 +453,7 @@ the specific language governing permissions and limitations under the Apache Lic
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$(data()).each2(function(i, datum) { process(datum, filtered.results); });
|
$(data().results).each2(function(i, datum) { process(datum, filtered.results); });
|
||||||
query.callback(filtered);
|
query.callback(filtered);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user