很简单demo报错



  • 报错 cannot read property 'row identities' of undefined react native

    0_1455757784313_Simulator Screen Shot Feb 18, 2016, 9.08.45 AM.png

    代码如下

    /**
     * Sample React Native App
     * https://github.com/facebook/react-native
     */
    'use strict';
    import React, {
      AppRegistry,
      Component,
      StyleSheet,
      Text,
      View,
      ListView,
    } from 'react-native';
    
    var HOT_MOVIES_URL = "https://api.github.com/search/repositories?q=bawn"
    
    class Movies extends Component {
      render() {
        if (this.state.dataSource.getRowCount() === 0) {
          return (
            <View style={styles.container}>
            <Text>
            加载中....
            </Text>
            </View>
          );
        }
        else {
          return (
            <View style={styles.container}>
            <ListView>
              dataSource={this.state.dataSource}
              renderRow={this.renderRow}
            </ListView>
            </View>
          );
        }
      }
      constructor(props){
            super(props);
            this.state = {
              dataSource: new ListView.DataSource({
                rowHasChanged: (row1, row2) => row1 !== row2,
              }),
            };
        }
      componentWillMount() {
        fetch(HOT_MOVIES_URL)
          .then((response) => response.json())
          .then((responseData) => {
            if (responseData.items) {
              this.setState({
                dataSource: this.state.dataSource.cloneWithRows(responseData.items),
              });
            }
          })
          .done();
      }
    
      renderRow(repo: Object) {
          return (
            <View>
            <View style={styles.row}>
            <View style={styles.textcontainer}>
              <Text style={styles.title}>{repo.name}</Text>
              <Text style={styles.subtitle}>{repo.name}</Text>
            </View>
            </View>
          <View/>
          </View>
          );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
      },
      textcontainer: {
      paddingLeft: 10,
      },
      row: {
        alignItems: 'center',
        backgroundColor : 'white',
        flexDirection: 'row',
        padding : 5,
      },
      welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
      },
      instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
      },
      title: {
        fontSize: 20,
        marginBottom: 8,
        fontWeight: 'bold'
      },
      subtitle: {
        fontSize: 16,
        marginBottom: 8,
      },
    });
    
    AppRegistry.registerComponent('Movies', () => Movies);
    
    

    用的ES6的写法,不知道错在哪里


  • administrators

    报错还是贴截图吧



  • 问题修改, 已贴图


  • administrators

    0_1455769675140_00BB95E2-B867-43B1-951A-BE6BA9FB602B.png



  • 原来是这个问题,非常感谢


登录后回复