नीचे मेरे कोड का एक स्निपेट है। त्रुटि मैं हो रही है, कि जब मैं खोज की जाएगी तथा विधि _searchData
कहते हैं, इसे सफलतापूर्वक विधि _lookUpSuccess
कॉल है, लेकिन उसके बाद निम्न त्रुटि देता है:अपरिभाषित या शून्य संदर्भ की संपत्ति प्राप्त करने में असमर्थ - विंडोज 8 जेएस/सीएसएस ऐप
जावास्क्रिप्ट रनटाइम त्रुटि: संपत्ति प्राप्त करने में असमर्थ '_displayResult' अपरिभाषित की या शून्य संदर्भ
जब यह _displayResult
विधि को कॉल करने का प्रयास करता है।
ऐसा क्यों हो सकता है?
(function() {
// make this an object property/method eventually
var displayResult = function (queryResult) {
for (var i = 0; i < holder.length; i++) {
//document.querySelector(".item-content .title").textContent = "FilmApp";
document.querySelector(holder[i]).textContent = queryResult[i];
}};
// Creates a new page control with members
ui.Pages.define(searchPageURI, {
//...
_searchData: function (queryText) {
searchBase = 'http://www.example.com/web-service2.php?termID=';
searchFormat = 'JSON';
searchFormatPiece = '&format=' + searchFormat;
if (!window.Data) {
var searchUrl = searchBase + queryText + searchFormatPiece;
WinJS.xhr({ url: searchUrl }).done(this._lookUpSuccess, this._lookUpFail, this._lookUpProgress);
}else{
document.querySelector(".titlearea .pagetitle").textContent = "There has been a computer malfunction - sort it the **** out!";
}
},
_lookUpSuccess: function xhrSucceed(Result) {
var response = JSON.parse(Result.responseText);
if (response.response[0].Message === "Found") {
for (var x in response.response[1].term) {
content.push(response.response[1].term[x]);
};
this._displayResult(content);
//displayResult(content);
return content;
} else {
content.push("Not Found", "Not Found");
return content;
}
},
_lookUpFail: function xhrFail(Result) { document.querySelector(".titlearea .pagetitle").textContent = "Got Error"; },
_lookUpProgress: function xhrProgress(Result) { document.querySelector(".titlearea .pagetitle").textContent = "No Result 2"; },
_displayResult: function (queryResult) {
var holder;
holder = [DefDiv, DescDiv];
for (var i = 0; i < holder.length; i++) {
//document.querySelector(".item-content .title").textContent = "FilmApp";
document.querySelector(holder[i]).textContent = queryResult[i];
};
},
});
// End of UI.page.define
// #2 This method is run on application load
WinJS.Application.addEventListener("activated", function (args) {
if (args.detail.kind === appModel.Activation.ActivationKind.search) {
args.setPromise(ui.processAll().then(function() {
if (!nav.location) {
nav.history.current = { location: Application.navigator.home, initialState: {} };
}
return nav.navigate(searchPageURI, { queryText: args.detail.queryText });
}));
}
});
// #3
appModel.Search.SearchPane.getForCurrentView().onquerysubmitted = function (args) { nav.navigate(searchPageURI, args); };
})();
बहुत बहुत धन्यवाद, इसने काम किया है, हालांकि उसने 'lookUpSuccess' विधि में एक नई समस्या पेश की है। अब मुझे 'संपत्ति प्राप्त करने में असमर्थ' प्रतिक्रिया 'अपरिभाषित या शून्य संदर्भ' का टेक्स्ट 'जैसे' उस संशोधन को रोक दिया गया है, '_lookUpSuccess' – James
@James - हाँ, आपको परिणाम मान के साथ पास करना होगा। मैंने यह दिखाने के लिए अपना जवाब संशोधित कर दिया है कि आप यह कैसे करते हैं। नोट: यदि आपके पास 'this' ptr की आवश्यकता है, तो आपके पास' _lookUpFail' और '_lookUpProgress' के साथ एक ही समस्या है। – jfriend00
यह पूरी तरह से काम किया, इस मदद के लिए बहुत बहुत धन्यवाद। जानने के लिए समस्या निवारण का एक बहुत ही उपयोगी बिट! – James