lundi 18 janvier 2016

Access variable outside promise.then() callback [duplicate]

This question already has an answer here:

I want to access my "datafields" variable as below;

var datafields = {};
var promise = this.doXhrPost(someData, '/json/myService');
promise.then(function(response) {
datafields["pmt"] = response.someVal;   
});

this.getActions().forEach(function(action) {
// I get an error for the below line Cannot read property 'push' of undefined TypeError
datafields["pmt"].push({
    name: 'xyz'
});
});     

So this is actually an Ember class and all the code is inside the route "activate" hook with getActions() as method of this class

getActions: function() {
    //some code to build someArray with objects
    return someArray;
}

But I get Cannot read property 'push' of undefined TypeError, when trying to do

datafields["pmt"].push({
})




Aucun commentaire:

Enregistrer un commentaire