Undefined不是一个对象(eveluating'e.foreach')反应原生地图功能

时间:2018-02-13 12:04:14

标签: react-native react-native-android

我想在文本框中显示用户点击的类别。所以我使用的是onPress={() => this.setState({ onPressItem: category.name })}。但我收到的错误是Undefined is not an object (eveluating 'e.foreach')我在这里错过了什么?

  export default class MyShowroom extends Component {
    constructor(props) {
        super(props);
        this.state = {
          onPressItem: 'shirt',
          categories: [{displayName: 'Shirt', name: 'shirt', uri: 'https://s3.eu-central-1.amazonaws.com/shirt.png'},
                     {displayName: 'belt', name: 'belt', uri: 'https://s3.eu-central-1.amazonaws.com/belt.png'},
                     {displayName: 'blazer', name: 'blazer', uri: 'https://s3.eu-central-1.amazonaws.com/Blazer.png'}]
        }
    }
    render() {
      return (
        <Row>
          <View style={styles.title}>
            <Text style={styles.show}>My Showroom</Text>
          </View>
          <View style={{flex: 1, flexDirection: 'row', padding: 50}}>
          {
            this.state.categories.map((category, i) => {
              return(
               <TouchableOpacity activeOpacity = { .5 } key={i} onPress={() => this.setState({ onPressItem: category.name })}>
                 <Image source={{uri: category.uri}} style= {styles.categoryImage}/>
                 <Text key={i} style={styles.categoryText}>{category.displayName} </Text>
               </TouchableOpacity>);
           })
          }
         </View>
      </Row>
    );
  }
}

0 个答案:

没有答案