作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,我为我的应用程序创建了一个图库,允许用户从其社交媒体帐户获取图像。我的应用程序使用 Redux。当用户登录时,我已经在我的应用程序商店中保存了 facebook ID 和 TOKEN。当我从父类调用 this.props.fbLoginData.TOKEN 时,我没有问题。但是我总是得到
undefined is not an object(evaluating 'this.props.fbLoginData.TOKEN')
当我从我的 child 类(class)调用 this.props 时。
这是我的画廊(父级)类(class):
_renderScene = ({ route }) => {
switch (route.key) {
case '1':
return <View style={styles.page} />;
case '2':
return <View style={styles.page} />;
case '3':
return <FBPhotos />;
default:
return null;
}
};
render() {
return (
<TabViewAnimated
style={[ styles.container, this.props.style ]}
navigationState={this.state}
renderScene={this._renderScene}
renderHeader={this._renderHeader}
onRequestChangeTab={this._handleChangeTab}
initialLayout={initialLayout}
/>
);
}
这是我的 fbPhotos 类
componentWillMount(){
//this._facebookPhotoIDs();
fbToken = this.props.fbLoginData.TOKEN;
}
render(){
return (
prop to style the items.
<ListView contentContainerStyle={styles.list}
dataSource={this.state.dataSource}
renderRow={this._renderRow}
/>
);
}
我尝试绑定(bind) this.props.fbLoginData.TOKEN 但它会变空。如何从 fbPhotos 类获取 fbLoginData 状态?
最佳答案
在您的 renderScene
方法中:
_renderScene = ({ route }) => {
switch (route.key) {
case '1':
return <View style={styles.page} />;
case '2':
return <View style={styles.page} />;
case '3':
return <FBPhotos fbLoginData={this.props.fbLoginData} />;
default:
return null;
}
};
关于ios - 如何从 child 类调用this.props?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40649370/
我是一名优秀的程序员,十分优秀!