मैं ट्विटर द्वारा टाइपहेड का उपयोग कर रहा हूं। मैं इंटेलिज से इस चेतावनी में भाग रहा हूं। यह आइटम की मेरी सूची में अंतिम लिंक होने के लिए प्रत्येक लिंक के लिए "window.location.href" का कारण बन रहा है।उत्परिवर्तनीय चर बंद होने से सुलभ है। मैं इसे कैसे ठीक करूं?
मैं अपना कोड कैसे ठीक कर सकता हूं?
AutoSuggest.prototype.config = function() {
var me = this;
var comp, options;
var gotoUrl = "/{0}/{1}";
var imgurl = '<img src="/icon/{0}.gif"/>';
var target;
for (var i = 0; i < me.targets.length; i++) {
target = me.targets[i];
if ($("#" + target.inputId).length != 0) {
options = {
source: function (query, process) { // where to get the data
process(me.results);
},
// set max results to display
items: 10,
matcher: function (item) { // how to make sure the result select is correct/matching
// we check the query against the ticker then the company name
comp = me.map[item];
var symbol = comp.s.toLowerCase();
return (this.query.trim().toLowerCase() == symbol.substring(0, 1) ||
comp.c.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1);
},
highlighter: function (item) { // how to show the data
comp = me.map[item];
if (typeof comp === 'undefined') {
return "<span>No Match Found.</span>";
}
if (comp.t == 0) {
imgurl = comp.v;
} else if (comp.t == -1) {
imgurl = me.format(imgurl, "empty");
} else {
imgurl = me.format(imgurl, comp.t);
}
return "\n<span id='compVenue'>" + imgurl + "</span>" +
"\n<span id='compSymbol'><b>" + comp.s + "</b></span>" +
"\n<span id='compName'>" + comp.c + "</span>";
},
sorter: function (items) { // sort our results
if (items.length == 0) {
items.push(Object());
}
return items;
},
// the problem starts here when i start using target inside the functions
updater: function (item) { // what to do when item is selected
comp = me.map[item];
if (typeof comp === 'undefined') {
return this.query;
}
window.location.href = me.format(gotoUrl, comp.s, target.destination);
return item;
}
};
$("#" + target.inputId).typeahead(options);
// lastly, set up the functions for the buttons
$("#" + target.buttonId).click(function() {
window.location.href = me.format(gotoUrl, $("#" + target.inputId).val(), target.destination);
});
}
}
};
@ cdhowie की मदद, कुछ और कोड के साथ:
नीचे मेरी कोड है मैं क्लिक के लिए अपडेटर और भी href()
updater: (function (inner_target) { // what to do when item is selected
return function (item) {
comp = me.map[item];
if (typeof comp === 'undefined') {
return this.query;
}
window.location.href = me.format(gotoUrl, comp.s, inner_target.destination);
return item;
}}(target))};
याओ, (सामान्य टिप्पणी से संबंधित नहीं प्रश्न): 'matcher' में वही शामिल नहीं है 'अगर (टाइपऑफ comp ===' अपरिभाषित ') {...} 'सुरक्षा परीक्षण' हाइलाइटर 'और' updater' में शामिल है। कोड पर एक त्वरित नज़र पर, ऐसा लगता है कि यह एक निरीक्षण हो सकता है। –
@ बीटरूट-बीटरूट ओह्ह्ह्ह्ह्ह्ह अच्छा पकड़ !!! धन्यवाद!!! आश्चर्य की बात है कि जब कोई मैच नहीं है तो मुझे कोई त्रुटि नहीं मिली है =/ – iCodeLikeImDrunk
याओ, ऐसा लगता है कि आपके कोड में कहीं और अच्छी त्रुटि सहनशीलता है लेकिन "बेल्ट + ब्रेसेस" किसी को कभी चोट नहीं पहुंचाती है। –