如何让这反应ajax响应和设置状态

时间:2016-09-28 08:44:06

标签: javascript jquery ajax reactjs

class Videos extends React.Component{
    constructor(){
        super();
        videoslist:[];
    }


    _getVideo(skip,limit){

        var self= this;    
        var sess=localStorage.getItem("sessionId");

        $.ajax({
            method:'GET',
            url:'videos',
            data:{'sessionId':sess,
                 'skip':skip,
                 'limit':limit},
            success:function(res){
               this.setState({videoslist:res.data})
            }.bind(this)
        });       
   }
 componentWillMount(){
       this._getVideo(0,10);
   } 

未捕获的TypeError:无法读取属性' videoslist' of null Uncaught TypeError:无法读取属性' _currentElement'为null

1 个答案:

答案 0 :(得分:1)

你的状态初始化错误

constructor(){
    super();
    this.state = {
        videoslist: []
    }
}