0
我想要的功能,使一个新的JSON对象,看起来如此:Node.js&Redis&For循环与蓝鸟承诺?
{ T-ID_12 : [{ text: "aaaaa", kat:"a" }], T-ID_15 : [{ text: "b", kat:"ab" }], T-ID_16 : [{ text: "b", kat:"ab" }] }
这{ text: "aaaaa", kat:"a" }
在thesenjsondata这T-ID_12
是阵列Thesen_IDS的条目。我的解决方案到目前为止是:
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;
}
我知道,for循环比db.getAsync()更快。我如何使用redis权限的蓝鸟承诺,以便返回值具有我想要的所有数据?
函数的返回,现在是{ “isFulfilled”:假 “isRejected”:假 } – Arzan0
见我如何使用这个功能 –
THX编辑,它的工作,但我不得不“var thesenjsondata = JSON.parse(res);”更改为“var thesenjsondata = res;” – Arzan0