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