[英]React parent component props are not passing to child component
Getting data from ajax call and storing in the component state 从ajax调用获取数据并存储在组件状态
_getDataFromServer(){
reqwest({
url: 'http://127.0.0.1:8000/api/example/'
, type: 'json'
, method: 'get'
, contentType: 'application/json'
, crossOrigin: true
, withCredentials: false
, error: function (err) { }
, success: function (resp) {
const data = resp
this.setState({config:data})
}.bind(this)
})
}
componentWillMount(){
this._getDataFromServer()
}
and passing the json data in state to child component in the render method 并将状态中的json数据传递给render方法中的子组件
render() {
return (
<Panel>
<AppDynamic uiConfig={this.state.config}/>
</Panel>
);
}
But the props are empty in the child component.i cant understand why props are not passing to child component 但是道具在子组件中是空的。我无法理解为什么道具没有传递给子组件
Try to bind the context to _getDataFromServer
method inside the constructor. 尝试将上下文绑定到构造函数内的
_getDataFromServer
方法。
Javascript Java脚本
constructor(props){
super(props);
this._getDataFromServer = this._getDataFromServer.bind(this)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.