Aus dem folgenden Code i, das Versprechen zu lösen versuchen nur nach den Spielen seiner Daten aus der api Schleife gefüllt Objekt hat, wenn der Sinn macht, aber es hält leer Anzeige:Beheben Sie das Versprechen erst, nachdem die Variable ausgefüllt wurde?
{
info: summoner,
matchIds: { << used for loop below
0: matchIds['matches'][0].matchId,
1: matchIds['matches'][1].matchId,
2: matchIds['matches'][2].matchId,
3: matchIds['matches'][3].matchId,
4: matchIds['matches'][4].matchId,
5: matchIds['matches'][5].matchId,
6: matchIds['matches'][6].matchId,
7: matchIds['matches'][7].matchId,
8: matchIds['matches'][8].matchId,
9: matchIds['matches'][9].matchId
}
}
var getMatches = function(summoner) {
var promise = new Promise(function(resolve, reject){
var opt = {};
var games = {}; << object needs to be filled
for (var val in Object.keys(summoner['matchIds'])) {
var match = summoner['matchIds'][val];
opt.id = match;
api.getMatchById(opt, function(err, game) {
games[x] = game;
})
}
console.log(games);
resolve({games});
});
return promise;
};
@Elevant - Hat dies Ihre Frage beantwortet? – jfriend00