const objectPromise = obj => {
const keys = Object.keys(obj);
return Promise.all(Object.values(obj)).then(results => Object.assign({}, ...results.map((result, index) => ({[keys[index]]: result}))));
};
使用它
value1: string;
value2: string;
...
activate(): Promise<any> {
return objectPromise({value1: this.promise1, value2: this.promise2()})
.then(results => Object.assign(this, results));
}
在…上
搜索
蓝知更鸟
文档
,我偶然发现
Promsie.props
所以
value1: string;
value2: string;
...
activate(): Promise<any> {
return Promise.props({value1: this.promise1, value2: this.promise2()})
.then(results => Object.assign(this, results));
}
应该做你想做的事