0
我制作了一个反应原生应用程序并使用了redux路由。我对这些技术相当陌生。我正在一个页面上进行api调用并显示一个列表。点击列表项时,应用程序将重定向到显示详细信息的另一个页面。如何将第一页上收到的数据传递给详细信息页面以显示内容。这是我的第一页看起来像。另外我如何访问这第二页如何使用redux将接收的数据传递到另一个页面
class MovieDetails extends Component {
constructor(props) {
super(props)
this.state = {
results: [],
loading: true
}
}
_fetchData() {
fetch("http://example.com/data.json", {
method: "GET"
})
.then((response) => response.json())
.then((responseData) => {
console.log(responseData)
this.setState({
results: responseData,
loading: false
})
})
.done()
}
pushNewRoute(route) {
this.props.pushNewRoute(route)
}
componentDidMount() {
this._fetchData()
}
render() {
return (
<Container theme={theme} style={{backgroundColor: '#262626'}}>
<Image source={require('../../../images/img.png')} style={styles.container}>
<Header>
<Button transparent onPress={this.props.openDrawer} style={Platform.OS === 'android' ? headerStyles.aheaderIcon : headerStyles.iosheaderIcon} >
<Icon name="ios-menu" />
</Button>
<Text style={headerStyles.textHeader}>Movies</Text>
<Image
transparent
source={require('../../../images/Header-Logo.png')}
style={[headerStyles.logoHeader, Platform.OS === 'android' ? headerStyles.aheaderIcon : headerStyles.iosheaderIcon]} />
</Header>
<Content>
<View style={{backgroundColor: '#fff'}}>
{
this.state.results.map(function(data, index) {
return (
<TouchableOpacity
key={index}
style={{flexDirection: 'row'}}
onPress={() => this.pushNewRoute('movieDetails')}>
<Image source={{uri: data.thumb}} style={styles.movieImage} />
<View style={styles.movieContent}>
<Text numberOfLines={2} style={styles.movieHeader}>
{data.headline}
</Text>
<View style={{flexDirection:'row', marginLeft: -20, marginTop: 25}}>
<Icon name="ios-time-outline" style={ Platform.OS === 'android' ? styles.aHeadertimeIcon : styles.iosHeadertimeIcon} />
<Text style={styles.moviePosterLink}>{data.date} at {data.time}</Text>
</View>
</View>
</TouchableOpacity>
)
}, this)
}
</View>
</Content>
</Image>
</Container>
)
}
}
function bindAction(dispatch) {
return {
openDrawer:()=>dispatch(openDrawer()),
pushNewRoute:(route)=>dispatch(pushNewRoute(route))
}
}
export default connect(null, bindAction)(MovieDetails)
将是真棒,如果你能直接我以一个例子或状态如何我可以访问这 – vijar
我真的不认为公开回购,明确证明这一点。我实际上忽略了你的代码,并假定你已经将提取的数据存储到商店。但你没有。看看这个:github.com/reactjs/redux/tree/master/examples/real-world - 野兽 – beast