componentDidMount() {
$.ajax({
type: "GET",
url: "/tweets",
dataType: "json",
success: function (data){
//$('#tweetsList').append(data);
this.setState({tweetsList: data});
},
error: function (error) {
console.log(error);
}
});
}
上面的代碼塊給了我一個this.setState函數找不到的錯誤。我試圖從我的Tweets控制器呈現json到我的main.jsx文件。this.setState不是函數rails
ajax調用中此更改的上下文。您需要引用原始上下文。寫答案。 –