私はデータを得るために解決する必要がある約束をいくつか持っています。もちろん、私は便利ですpromise.all()
私に利用可能です。残念ながら、これらの約束のうちの1つは、別の一連の約束を返す。それらの約束を得ることは可能ですか?例えば他のデータ(promise.all)と共に約束の約束からデータを取得
:
var result = {};
let pName = getName(); // returns promise<string>
let pAge = getAge(); // returns promise<string>
let pSchools = getSchools; // returns promise<Array<promise<string>>>
return promise.all([pName, pAge, pSchool]).then(function(res) {
result["name"] = res[0];
result["age"] = res[1];
result["schools"] = [];
// This next section I don't think will work because it doesn't resolve "in time".
res[2].map(function(school) {
school().then(theSchool => result["schools"].push(theSchool))
});
return result;
}); // returns promise<{
// "name": "string",
// "age": "string",
// "schools": [string1, ..., stringN]
// }>
は、誰もがこのような何かを行うことがありましたか?どうやってそれをやったの?文字列の約束の配列のgetSchools
リターンの約束として
試してみます – Machtyn