反应:无法循环渲染项目

时间:2017-03-27 22:19:56

标签: reactjs

我有以下代码,Test startTest end都显示。此外,调试器通过areasindex正确循环。出于某种原因,它不会在{Object.keys(this.state.firstOccurrence.checklist).forEach语句中呈现任何内容。我错过了什么?

import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Toast } from 'native-base';

export default class Job extends Component {

  [setting state]      

  render() {
    return (
      <Container>
        {this.state.firstOccurrence != undefined &&
          <Content padder>
            <View style={styles.container}>
              <View>
                <Text>Test start</Text>
              </View>
              {Object.keys(this.state.firstOccurrence.checklist).forEach((area, index) => {
                debugger
                return (
                  <View key={index}>
                    <Text>Test {area}</Text>
                  </View>
                );
              })
              }
              <View>
                <Text>Test end</Text>
              </View>
            </View>
          </Content>
        }
      </Container>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    paddingTop: 65,
    flexDirection: 'column',
    alignItems: 'flex-start'
  }
});

1 个答案:

答案 0 :(得分:3)

abc ------------------- def ------------------- ghi ------------------- j 返回undefined。你想要.forEach