Javascript .map不显示列表(来自API)
提前谢谢!! 我有麻烦了,我不知道我的地图怎么了呵呵。我是一名新生(JS、React、Redux)。它应该显示一个列表(或者至少一个名字,任何东西),但什么都不会发生Javascript .map不显示列表(来自API),javascript,reactjs,redux,react-redux,Javascript,Reactjs,Redux,React Redux,提前谢谢!! 我有麻烦了,我不知道我的地图怎么了呵呵。我是一名新生(JS、React、Redux)。它应该显示一个列表(或者至少一个名字,任何东西),但什么都不会发生 import React, {Component} from "react"; import { connect } from "react-redux"; import { push } from "connected-react-router"; import { getTrips } from ".
import React, {Component} from "react";
import { connect } from "react-redux";
import { push } from "connected-react-router";
import { getTrips } from "../../actions/allActions";
import List from "@material-ui/core/List";
class ListTrips extends Component {
componentDidMount() {
this.props.getTripsAction();
}
render() {
return (
<List>
{
this.props.trips.map((trip) => {
return(<li>{trip.name}</li>)
})
}
</List>
);
}
}
const mapStateToProps = state => ({
trips: state.trips.trips
});
const mapDispatchToProps = dispatch => ({
getTripsAction: () => dispatch(getTrips()),
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(ListTrips)
import React,{Component}来自“React”;
从“react redux”导入{connect};
从“连接的路由器”导入{push};
从“../../actions/allActions”导入{getTrips}”;
从“@material ui/core/List”导入列表;
类ListTrips扩展组件{
componentDidMount(){
this.props.getTripsAction();
}
render(){
返回(
{
this.props.trips.map((trip)=>{
返回({trip.name} )
})
}
);
}
}
常量mapStateToProps=状态=>({
行程:state.trips.trips
});
const mapDispatchToProps=调度=>({
getTripsAction:()=>dispatch(getTrips()),
});
导出默认连接(
MapStateTops,
mapDispatchToProps
)(列表行程)
在render method和Check开始时创建ListTrips
?console.log(this.props.trips)的代码是什么?另外,不要忘记为
标记分配键,以便React可以跟踪它们。取而代之的是什么?如果您在浏览器的开发工具中检查元素,那么实际呈现为HTML的是什么?很快我将尝试您建议的所有内容,谢谢大家=)