【发布时间】:2015-03-18 12:22:14
【问题描述】:
我喜欢在事件触发onDrag 时将属性属性/道具/状态值从子组件发送到父组件。我找不到这方面的适当文档。
这是我的代码:
/*** @jsx React.DOM */
var APP=React.createClass({
getInitialState:function()
{
return {url:'http://www.youtube.com/embed/XGSy3_Czz8k'}
},
handleDrag:function(vidurl)
{
alert(vidurl); //i need to get child component url here.
},
render:function(){
return <div>
<VideoFrame src={this.state.url} />
<hr/>
<videos handle={this.handleDrag(vidurl)} />
</div>
}
});
var VideoFrame=React.createClass({
render:function(){
return <div>
<iframe width="420" height="315" src={this.props.src}>
</iframe>
</div>
}
});
var videos=React.createClass({
getInitialState:function()
{
return {vidurl:'http://www.youtube.com/embed/XGSy3_Czz8k'}
},
render:function()
{
return <img src="http://upload.wikimedia.org/wikipedia/en/a/a6/Size_Small.PNG" onDrag={this.props.handle.bind(this.state.vidurl)}></img> //trying to send state value from here
}
});
React.renderComponent(<APP />, document.body);
我希望我的代码是清晰的。
【问题讨论】:
-
你能在 jsfiddle 中重现这个问题吗?
-
这段代码读起来会更清晰,因为它使用了一致的缩进。
标签: javascript reactjs react-jsx reactjs-native