【发布时间】:2018-09-12 09:20:08
【问题描述】:
我以这种方式从 api 获得响应
data:Array(3)
0:"new"
1:"ruby"
2:"ruby"
我想在 jsx 表达式内的 tr 元素下显示此数据。我做了一个循环来遍历这样的数组
let course = [];
let userid = this.props.match.params.userid;
axios.get("someapi") //the api to hit request
.then((response) => {
console.log(response);
for (var i = 0; i < response.data.length; i++) {
console.log(response.data[i]);
course.push(response.data[i]);
}
console.log("course", course);
this.setState({ course: course });
console.log("state course", this.state.course);
});
我得到了console.log 中的所有值,带有“course”和“state course”,但无法将它映射到 tbody 中以在 tr 标签中显示它。我想在这个里面渲染它
<tbody>
<tr>new,ruby and ruby should be displayed here as a list</tr>
</tbody>
我做错了什么?
【问题讨论】:
-
发布你所有的代码,尤其是你正在渲染的代码
-
你没有映射
this.state.course...
标签: javascript reactjs jsx