我有以下代码调用一个休息 api,然后使用结果数据并将值提供给后续的 api 调用。不知道如何使这项工作..!您可以在第二种方法中看到我的评论,这会显示数据,但是因为这是一个承诺,所以我不确定如何将其传回?
有任何想法吗?谢谢
代码片段
componentDidMount() {
myMethod();
}
getBookings(id) {
getCustomerBookings(id).then(res => {
console.log(res); // displays the data correctly
return res;
});
}
myMethod() {
var self = this;
var myArray = [];
getCustomers().then(result => {
for(var index = 0; index < result.length; index++) {
myArray.push(<div className="col">
{result[index].customerId} // displays customer id as expected
{this.getBookings(result[index].customerId)} // attempt
</div>
self.setState({customers: myArray});
});
}
UYOU
偶然的你
相关分类