【发布时间】:2019-07-13 02:47:19
【问题描述】:
我已经尝试了三天来解决我不能将多个元素放入一个数组中,但是如果我只能放入一个当我输入返回 this.state.dat.nombre 或 dat.carrera 时它可以工作,但是如果我尝试使用我没有得到的地图功能
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
dat: [],
isFetch: true
};
}
componentDidMount() {
var url =
"https://cors-anywhere.herokuapp.com/http://sipla.cuci.udg.mx/sc/horariop.php?c=219359735&k=0d8ce4fab5f4df9ce711cae81e044e1a";
fetch(url, {
method: "GET",
headers: {
"X-Requested-With": "XMLHttpRequest"
}
})
.then(response => {
return response.json();
})
.then(art => {
this.setState({ dat: art, isFetch: false });
});
}
render() {
if (this.state.isFetch) {
return "cargando....";
}
this.state.dat.map(art => {
return (
<tr key={art.codigo}>
<td>{art.nombre}</td>
<td>{art.carrera}</td>
<td>{art.horarios}</td>
</tr>
);
});
}
}
export default App;
【问题讨论】:
-
当你设置
art时记录一下它是什么。是数组吗?
标签: javascript reactjs meteor