【发布时间】:2016-04-10 19:59:47
【问题描述】:
我正在创建一个 React 文件树,并将树设置为 React 组件。树可以采用 contents 属性,它是一个字符串数组或其他 <Tree /> 组件(这启用了嵌套文件结构 UI)。这些树组件可以无限嵌套。
我需要在嵌套树组件的子级上注册一个点击事件,但我无法让它在第一级嵌套之外工作。我正在处理的一个简化示例:
//In App - the top level component
const App = React.createClass({
_handleChildClick () {
console.log("this is where all child clicks should be handled");
},
render () {
return (
<Tree
handleChildClick={this._handleChildClick}
contents={[
<Tree />
]}
/>
);
}
});
//And in the tree component
<div onClick={this.props.handleChildClick}></div>
If you want to see more detail - here's the github repo.
我尝试研究这个问题并看到人们使用{...this.props},但我不确定这是否适用于我的场景 - 如果适用,我无法让它工作。
感谢您对此的任何帮助。
【问题讨论】:
标签: javascript reactjs tree onclick