我有以下組成部分:陣營組件所呈現舊道具
var Answer = React.createClass({
getInitialState: function(){
return {edit: false, comments: []}
},
componentWillMount: function(){
$.ajax({
context: this,
method: 'GET',
url: '/answers/' + this.props.answer.id + '/comments/',
success: function(data){
this.setState({comments: data});
}
});
},
render: function(){
return (
<div>
//This renders with initial comments in the state, the empty array
<Comments comments={this.state.comments} />
</div>
);
},
通知我如何從服務器獲取意見,並把它們保存到狀態,然後將它們作爲道具的意見。問題是道具正在作爲舊狀態傳遞,而不是從服務器獲取的新狀態。我在這裏錯過了什麼?
您的評論組件的外觀如何? – Kafo