Reactjsを学んでいます。Rails で 1 つのサンプル 反応アプリを実装しました。解決策を見つけるためにたくさん検索しましたが、何も見つかりませんでした。関数から別のコンポーネントを呼び出したかったのonClick
です。しかし、何も起こりません。それは私が達成しようとしていることですか?はいの場合は、私が間違っている場所を教えてください。そうでない場合は、どの方法で実装できますか。これが私のコードです:
var Comment = React.createClass({
render: function () {
return (
<div id={"comment_"+ this.props.id }>
<h4>{ this.props.author } said:</h4>
<p>{ this.props.desc }</p>
<a href='' onClick={this.handleDelete}>Delete</a> | #this is for delete which works great
<a href='' onClick={this.handleEdit}>Edit</a>
# If I put here then it works fine <UpdateComments comments={ this.props} /> but I don't want it here
</div>
)
},
handleDelete: function(event) {
$.ajax({
url: '/comments/'+ this.props.id,
type: "DELETE",
dataType: "json",
success: function (data) {
this.setState({ comments: data });
}.bind(this)
});
},
handleEdit: function(event) {
var Temp = React.createClass({
render: function(event){
return(<div>
<UpdateComments comments={ this.props} /> #here I want to call UpdateComments component
</div>
)
}
});
}
});
更新: 以下のトリックを試してみると、コンポーネントが呼び出されますが、ページがリロードされ、呼び出されたコンポーネントが再び消えます:(
handleEdit: function() {
React.render(<UpdateComments comments={ this.props} /> , document.getElementById('comment_'+ this.props.id));
}
その他の詳細が必要な場合は、お気軽にお問い合わせください。前もって感謝します。:)