Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function blub(URI){ var array = [] mopidy.library.lookup(URI).then(function(blabla){ array.push(blabla); console.log(array[0]); // Ausgabe im Browser korrekt! }); console.log(array); // Ausgabe im Browser = Array[ ] console.log(array[0]); //Ausgabe im Browser = undefined } |
Community-Fossil
Beruf: Teamleiter Mobile Applikationen & Senior Software Engineer
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function blub(URI){ var array = [] function callback(blabla){ array.push(blabla); console.log(array[0]); // Ausgabe im Browser korrekt! }; mopidy.library.lookup(URI).then(callback); console.log(array); // Ausgabe im Browser = Array[ ] console.log(array[0]); //Ausgabe im Browser = undefined } |
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Ok ich verstehe. Jedoch verstehe ich dann nicht, warum die erste Ausgabe, die noch in den {} der Function steht, korrekt ausgegeben wird?
...
Zurück kommt ein Objekt(blabla) in dem die ID3tags der Musikdatei stehen.
Quellcode |
|
1 2 3 4 5 6 7 8 9 |
var array = []; function HandleData(blabla) { array.push(blabla); } mopidy.library.lookup(URI).then(HandleData); // Ruft HandleData auf sobald Daten da sind console.log(array); // Leer, da HandleData noch nicht aufgerufen wurde |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
var array = []; function HandleData(blabla) { array.push(blabla); } function CreateTable() { console.log(array); } var promiseArray = [] var promise = mopidy.library.lookup(URI).then(HandleData); promiseArray.push(promise); promise = mopidy.library.lookup(URI2).then(HandleData); promiseArray.push(promise); Promise.all(promiseArray).then(CreateTable); |
Werbeanzeige