我想从类函数外部获取子组件文件
函数saveSurveyData(survey)需要调用父函数 handletabs ()
class Parent extends React.Component {
constructor(props){
super(props);
this.handletabs = this.handletabs.bind(this);
}
handletabs = () => {
console.log('expecting call from Child component - function
}
render() {
return (
<Tab eventKey={1} title="child">
<Child handletabs={this.handletabs} />
</Tab>
)
}
}
// Child Component
import React from 'react';
import * as Survey from "survey-react";
var surveyValueChanged = function (sender,options) {
saveSurveyData(survey);
};
// critical surveyjs function
function saveSurveyData(survey) {
var data = survey.data;
//need to call handletabs() (parent) in this function which is outside of Child Component Class
//handletabs={this.handletabs}
this.handletabs(); // HOW ?
}
class Child extends React.Component {
constructor(props){
super(props);
}
render()
{
return(
<Survey.Survey model={survey}
onValueChanged={surveyValueChanged} />
)
}
}
我一直在尝试ref,props和state-我只是不了解如何在子组件之外执行此操作。