I am trying to send JSON data that's been loaded via dojo/request/xhr to a method within my custom class.
when I receive the data inside the .then()
function I do not have access to my class instance methods since the data is only contained inside the .then()
function call.
require([
"dojo/_base/declare",
"dojo/request/xhr"
], function(declare, xhr) {
declare("rpg.game",null, {
/**
*
* @param {type} domNode
* @returns {undefined}
*/
constructor: function(domNode) {
domNode.innerHTML = "hello world";
},
/**
*
* @param {type} _url
* @returns {undefined}
*
*/
loadData: function(_url) {
xhr(_url, {
handleAs: "json"
}).then(function(data){
// Do something with the handled data
console.log(data); // <-- How can I send this data to my class?
this.saveData(data); // <-- this does not work
}, function(err){
// Handle the error condition
}, function(evt){
// Handle a progress event from the request if the
// browser supports XHR2
});
},
saveData: function(data) {
this.data = data;
}
});
});
I want to send the data to the method saveData
but when I call the method, it is "undefined" within the .then()
call.