1
0
mirror of synced 2024-11-22 21:16:10 +03:00

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:
Lee Baker 2013-02-16 11:56:17 +11:00 committed by Igor Vaynberg
parent 7d908da52f
commit 6278e7cca0

View File

@ -406,25 +406,26 @@ 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)) { 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)) {
tmp = data; tmp = data;
data = {results:tmp}; data = { results: tmp };
} }
if ($.isFunction(data) === false) { if ($.isFunction(data) === false) {
tmp = data; tmp = data;
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);
}; };
} }