React - 数组元素显示长度= 0

时间:2017-03-08 21:40:30

标签: javascript reactjs

我一直在寻找这个问题的解决方案,但它仍然存在。我读到了setTimeout,但它没有用,或者可能是我没有以正确的方式使用它
这是我的代码

constructor(){
    super();
    this.state={
        message:[],
        socket: io.connect('http://'+ip+':3000')
    }
    this.Submit = this.submitMessage.bind(this);
}
componentWillMount(){
    let newMessage = this.state.message.slice();
    fetch('/get',{method:'POST'})
        .then(function(res){
            return res.json()
        }).then(function(body){
            _.map(body,(x,i)=>
                newMessage.push({'name':body[i].name, 'content':body[i].content})
            )
        })
    this.setState({message : newMessage});
}   

然后返回
enter image description here
任何人都可以帮助我?

0 个答案:

没有答案
相关问题