【发布时间】:2020-01-02 03:55:21
【问题描述】:
我正在尝试使用引导程序将 JSON 从 API 调用映射到返回。我希望名称一一映射到所有列和行,直到显示所有数据。目前,它正在映射所有 3 列中的所有数据(名称)。
componentDidMount() {
fetch(API + 'ts=' + date + 'apikey=' + pubKey + 'hash=' + hash)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
char: result.data.results,
});
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
}
render() {
const { error, isLoaded, char } = this.state;
return (
char.map(char =>
<Container>
<Row>
<Col md="4"> <h2>{char.name}</h2></Col>
<Col md="4"> <h2>{char.name}</h2></Col>
<Col md="4"> <h2>{char.name}</h2></Col>
</Row>
</Container>
)
)
}
}
【问题讨论】:
-
“希望名称一一映射到所有列和行”。这是什么意思?
-
包含 JSON 结果/结果数组以及您想要映射的属性可能会有所帮助。目前尚不清楚您的预期结果应该是什么。你想“一一”映射什么?
标签: javascript reactjs dictionary