我有一个组件,单击一个按钮时会打开一个模态,唯一的问题是我需要一个按钮来触发另一个组件上的方法:
var QueueReveal = React.createClass({
getInitialState: function() {
return { clock: "0H 0M 0S" }
},
componentDidMount: function(e) {
$(document).foundation();
},
enterQueue: function(e) {
$('#Queue').foundation('open');
// Start Timer
},
leaveQueue: function(e) {
$('#Queue').foundation('close');
var data = {
msgType: "LeaveQueue",
data: {}
}
queueConn.send(JSON.stringify(data));
},
render: function() {
return (
<div>
<h1 className="text-center">You Are Now In Queue</h1>
<p className="text-center"><small>You will be notified when a potential party has been found</small></p>
<span className="line-breaker"></span>
<br/>
<h1 className="text-center">{this.props.counter}</h1>
<br/>
<a className="alert button expanded" onClick={this.leaveQueue}>Leave Queue</a>
</div>
)
}
});
ReactDOM.render(<QueueReveal/>, document.getElementById('Queue'));
var EnterQueueButton = React.createClass({
render: function() {
return (
<a href="#" id="enterQueueButton"><i className="fa fa-clock-o"></i> Enter Queue</a>
// I would like this link to trigger `QueueReveal.enterQueue`
)
}
})
ReactDOM.render(<EnterQueueButton/>, document.getElementById('EnterQueueButton'));
我希望EnterQueueButton
在点击时触发QueueReveal.enterQueue
,但我不确定如何解决这个问题。