0
我有這個流星方法:如何使用流星進行API調用和響應
Meteor.methods({
'RESTcall':function() {
this.unblock();
return Meteor.http.call("GET", "http://www.viaggiatreno.it/viaggiatrenonew/resteasy/viaggiatreno/soluzioniViaggioNew/228/458/2017-05-31T00:00:00");}});
並與在渲染功能的按鈕調用這樣的功能的陣營Component.jsx:
search(){
Meteor.call("RESTcall", (error, response)=>{
console.log(response); //this works
this.setState({results: response}); //this throws an exception
}
});
}
問題是我能做些什麼來使用回調函數來回報它的內容。
在此先感謝。
在你的代碼中你使用了'console.log(results)',但是沒有'results'定義在任何地方。 'console.log(response)'的輸出是什麼?拋出什麼樣的異常? – tomsp
對不起是console.log(響應)的作品,它是一個JSON響應 – dibbi
你能提供例外嗎?你的電話似乎很好。 This.setState應該工作,因爲你正在使用一個箭頭函數。我想這個問題來自http調用,也許是一個CORS問題。 –