React native 导航无法处理ListView中的行

React native 导航无法处理ListView中的行,react-native,React Native,我有一个包含在ListView组件中的元素列表。我的元素是用.json中的数据构建的 我的列表屏幕如下所示: ListBillScreen.js 我想使用以下函数进行重定向: goAdd(){ this.props.navigator.push({ screen: 'BillScreen' }); } 但如果这样做,我会有一个错误,告诉我this.props.navigator在这种情况下不起作用。但在其他课程中,我会这样做,一切都很好 有人有解决办法吗?谢谢大家 您需要将navigat

我有一个包含在ListView组件中的元素列表。我的元素是用.json中的数据构建的

我的列表屏幕如下所示:

ListBillScreen.js

我想使用以下函数进行重定向:

goAdd(){
  this.props.navigator.push({ screen: 'BillScreen' });
}
但如果这样做,我会有一个错误,告诉我this.props.navigator在这种情况下不起作用。但在其他课程中,我会这样做,一切都很好


有人有解决办法吗?谢谢大家

您需要将
navigator
作为道具传递到Row.js

  <ListView
    style={styles.listView}
    dataSource={this.state.dataSource}
    renderRow={(data) => <Row {...data} navigator={this.props.navigator}/>}
    renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator} />}
  />
}
RenderParator={(sectionId,rowId)=>}
/>

谢谢,就是这样!再次感谢
import React from 'react';
import { View, Text, StyleSheet, Image, Alert, TouchableHighlight, Navigator} from 'react-native';

import styles from './Styles/RowStyles'

const Row = (props) => (
<TouchableHighlight onPress={() => Alert.alert("Redirection " + 
props.name)}>
 <View style={styles.container}>
  <Image source={{ uri: props.picture}} style={styles.photo} />
  <Text style={styles.text}>
   {`${props.name} / ${props.price} euros`}
  </Text>
 </View>
</TouchableHighlight>
);

export default Row;
{() => Alert.alert("Redirection " + props.name)}>
goAdd(){
  this.props.navigator.push({ screen: 'BillScreen' });
}
  <ListView
    style={styles.listView}
    dataSource={this.state.dataSource}
    renderRow={(data) => <Row {...data} navigator={this.props.navigator}/>}
    renderSeparator={(sectionId, rowId) => <View key={rowId} style={styles.separator} />}
  />