Arrays 列表未呈现

Arrays 列表未呈现,arrays,reactjs,Arrays,Reactjs,我得到的错误是: 对象作为子对象无效,如果要呈现子对象集合,请改用数组 这里res是一个json,它有嵌套的数组,所以我使用了0.foreach来提取它,状态正在成功更新,但问题在于显示它 class ViewExchange extends React.Component{ state={list:[],refresh:false} componentWillMount(props){ if(_.isEmpty(Cookies.get

我得到的错误是:

对象作为子对象无效,如果要呈现子对象集合,请改用数组

这里res是一个json,它有嵌套的数组,所以我使用了0.foreach来提取它,状态正在成功更新,但问题在于显示它

    class ViewExchange extends React.Component{ 
      state={list:[],refresh:false}
      componentWillMount(props){
    
        if(_.isEmpty(Cookies.get())){
         this.props.history.push("/signup")
        }
        else{

        let platform = Cookies.get('platform')
 
        axios.post('http://localhost:3001/user/viewexchange',{platform})
        .then(res=>{
 
          this.setState({list:res.data})
          _.forEach(this.state.list,(value)=>{
            _.forEach(value.url,(e)=>this.setState({list:[e]}))
            })
        })
        }
      }

        renderList=()=>{
          console.log("in method")
        return this.state.list.map((item,key)=>{
        
          return <div key={key}>{item}</div>
        })
        }
    
     render(){

      return (
        <div>
          {this.renderList()}
        </div>
    );
      }
}
export default withRouter(ViewExchange);
类视图交换扩展了React.Component{
状态={list:[],刷新:false}
组件安装(道具){
if(u.isEmpty(Cookies.get())){
this.props.history.push(“/signup”)
}
否则{
let platform=Cookies.get('platform')
轴心柱http://localhost:3001/user/viewexchange“,{platform})
。然后(res=>{
this.setState({list:res.data})
_.forEach(此.state.list,(值)=>{
_.forEach(value.url,(e)=>this.setState({list:[e]}))
})
})
}
}
renderList=()=>{
console.log(“登录方法”)
返回此.state.list.map((项,键)=>{
返回{item}
})
}
render(){
返回(
{this.renderList()}
);
}
}
使用路由器导出默认值(ViewExchange);

当您试图在jsx中显示一些不是有效对象键(而是对象本身)的内容时,通常会出现此错误。在您的情况下,它将类似于:

return this.state.list.map((item,key)=>{ return <div key={key}>{item.index}</dv> });  // instead of item, you have to use item.index which is an existing key of object
返回this.state.list.map((项,键)=>{return{item.index});//您必须使用item.index,而不是item,它是对象的现有键

这里的
项。index
是您希望从对象中显示的索引,不要忘记提供
键,如果没有
键,它将显示一条警告,同时性能也会受到影响。

您在
这个.state.list中有什么?很难用有限的信息帮助您…同时提供
this.state.list