来自智能合约的数据显示类型ERror:无法读取未定义的属性'map'



我有一个带有智能合约的DApp,它持有一些报价(id、价格、所有者等(。我想在我的DApp中显示报价。

首先,我调用智能合约,并使用JavaScript:将所有报价提取到一个数组中

// Load offers
for (var i = 1; i <= offerCount; i++) {
const offer = await contract.methods.offers(i).call()
this.setState({
offers: [...this.state.offers, offer]
})
}

然后我想在一个表中显示该数组的内容:

<table className="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Price</th>
<th scope="col">Owner</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{
this.props.offers.map((offer, key) => {
return (
<tr key={key}>
<th scope="row">{offer.id.toString()}</th>
<td>{this.state.offers}</td>
</tr>
)
})
}
</tbody>
</table>

我得到错误

TypeError:无法读取未定义的属性"map">

我不知道如何在表上正确显示数据。

库:React
操作系统:XUbuntu
浏览器:Chrome

TypeError:无法读取未定义的属性"map">

此错误是因为This.props.offers未定义。

我想你必须用这个。州。费。

{
this.state.offers.map((offer, key) => {
return (
<tr key={key}>
<th scope="row">{offer.id.toString()}</th>
<td>{this.state.offers}</td>
</tr>
)
})
}

最新更新