【发布时间】:2019-07-14 10:35:48
【问题描述】:
Twitch API 最多显示 60 条记录和一个 _next 光标用于分页。我找不到使用 map 函数在 React 中使用光标映射所有结果的方法。
componentDidMount() {
this.getComments();
}
getComments(){
const api = 'https://api.twitch.tv/v5/videos/'+ this.state.value +'/comments?client_id='+ this.state.cid;
fetch(api, {
method: 'get',
headers: {"Client-ID": this.state.cid}
})
.then((response) => response.text())
.then((responseText) => {
this.setState({hits : (JSON.parse(responseText)), api: api})
});
}
render(){
const { hits } = this.state;
console.log({hits});
return (
<div>
<ul id="results">
{ hits && hits.comments && hits.comments.length !== 0 ?
hits.comments.map(hit =>
<li key={hit._id}>
<span>[{this.convertSeconds(hit.content_offset_seconds)}] - {hit.message.body}</span>
</li>
)
:
<div>No Comments Found</div>
}
</ul>
</div>
);
}
如何使用 _next 光标和这种映射技术进行映射? 或者有什么不同的方法可以实现吗?
以下是 JSON 响应..
【问题讨论】:
-
你能发布你的 JSON 响应吗?
-
已添加...谢谢
标签: javascript reactjs api twitch twitch-api