当我试图从父组件中调用achild组件时,我正在使用electron-es6-react,它可以帮助我,这是我做过的样本,
export default class Main extends React.Component {
constructor(props) {
super(props);
this.state = {
result: [{"name":hhhh","date":"12-05-2015"}];
}
}
render(){
return(
<fixedTable result={this.state.result}/>
)
}
}
class fixedTable extends React.Component{
render(){
alert("child);
return(
<div>hai</div>
)
}
}
任何帮助必须得到赞赏
答案 0 :(得分:1)
您需要在fixedTable
类的范围内定义Main
组件:
export default class Main extends React.Component {
constructor(props) {
super(props);
this.state = {
result: [{"name":hhhh,"date":"12-05-2015"],
};
class fixedTable extends React.Component{
render(){
alert("child);
return(
<div>hai</div>
)
}
}
}
render(){
return(
<fixedTable result={this.state.result}/>
)
}
}
答案 1 :(得分:1)
您的反应名称组件必须以大写字符开头。这就是你的子组件没有被调用的原因。除此之外,你需要纠正代码中的几个输入错误,并且不要在状态声明中包含;
class Main extends React.Component {
constructor(props) {
super(props);
this.state = {
result: [{"name":"hhhh","date":"12-05-2015"}]
}
}
render(){
return(
<FixedTable result={this.state.result}/>
)
}
}
class FixedTable extends React.Component{
render(){
alert("child");
return(
<div>hai</div>
)
}
}
ReactDOM.render(<Main/>, document.getElementById('app'));
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.8/react-dom.min.js"></script>
<div id="app"></div>
&#13;