Ich mag eine Funktion, die ein neues JSON-Objekt, das so aussieht macht:Node.js & Redis & For Loop mit Bluebird Versprechen?
{ T-ID_12 : [{ text: "aaaaa", kat:"a" }], T-ID_15 : [{ text: "b", kat:"ab" }], T-ID_16 : [{ text: "b", kat:"ab" }] }
Diese { text: "aaaaa", kat:"a" }
in thesenjsondata und diese T-ID_12
ist ein Eintrag der Array-Thesen_IDS. Und meine Lösung so weit ist:
function makeThesenJSON(number_these, Thesen_IDS){
var thesenjsondata;
var thesenids_with_jsondata = "";
for (i = 0; i < number_these; i++){
db.getAsync(Thesen_IDS[i]).then(function(res) {
if(res){
thesenjsondata = JSON.parse(res);
thesenids_with_jsondata += (Thesen_IDS[i] + ' : [ ' + thesenjsondata + " ], ");
}
});
}
var Response = "{ " + thesenids_with_jsondata + " }" ;
return Response;
}
Ich weiß, dass die for-Schleife ist schneller als die db.getAsync(). Wie kann ich die Bluebird Versprechungen mit Redis richtig nutzen, damit der Rückgabewert alle Daten hat, die ich möchte?
die Rückkehr der Funktion ist jetzt { „isFulfilled“: false „isRejected“: false } – Arzan0
meine bearbeiten Siehe, wie diese Funktion nutzen –
thx, es funktioniert , aber ich musste "var thesnjsondata = JSON.parse (res)"; ändern Sie zu "var thesnjsondata = res;" – Arzan0