简体   繁体   English

Listview DataSource错误-React Native

[英]Listview DataSource error - React Native

Hi,
Please checkout my code below
'use strict';
var React = require('react-native');
var Dimensions = require('Dimensions');
var windowSize = Dimensions.get('window');

var {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View,
  AsyncStorage,
  Alert,
} = React;

var api = require('./api.js');
var Row = require('./Row');

var Projects = React.createClass({  
  getInitialState: function() {     
    var ds = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, });
    return {      
      dataSource: ds,
      loaded: false,
      noData: false,
    }
  },

  componentDidMount: function() { 
    this.fetchData(); 
  },

  fetchData: function() { 
      fetch(api.url+"projects/"+this.props.token+"/", {
           headers: { 'Accept': 'text/json', 'Content-Type': 'text/json', },
       })
       .then((response) => response.json())
       .then((responseData) => { 
            //Alert.alert( 'projects response', JSON.stringify(responseData) );
            if(responseData.type == 'success'){

                if(responseData.result.length > 0){
                    this.setState({
                        loaded: false,

                    });
                }else{
                    this.setState({
                        loaded: true,
                        noData: true
                    });
                }

            }else if(responseData.type == 'error'){
                Alert.alert( 'Error', responseData.msg );
            }else{
                Alert.alert( 'Error', 'Oops! Something went wrong. Sorry for the inconvenience caused. Please try again.' );
            }
        })
        .catch((error) => { Alert.alert( '_valid_token error', error); });
  },

  loadingView: function(){
      return(<View style={styles.container}>
          <Text>Loading Projects...</Text>
      </View>);
  },

  noRecords: function(){
      return(<View style={styles.container}>
          <Text>No Projects to show</Text>
      </View>);
  },

  render: function() {    
    if(!this.state.loaded){
        return this.loadingView();
    }else{
        if(this.state.noData){
            return this.noRecords();
        }else{
            <ListView dataSource={this.state.dataSource} renderRow={this.renderRow} style={styles.listView} />
        }
    }

  },

  renderRow: function(row){
      return(<Row title={row.actions_name} subtitle={row.action_plan} tagline={row.company_name}/>);
  },
});

var styles = StyleSheet.create({
    container: {      
      flex: 1,
      backgroundColor: 'transparent',
      justifyContent: 'center',
      alignItems: 'center',
    }, 
    listView: {

    }
});

module.exports = Projects;
I am getting error right at

    var ds = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 !== row2, });

react-native version I am using is 0.20.0
and react-native-cli 0.1.10
Error screenshot as below
[![enter image description here][1]][1]

My Bad..
I didn't use return function in render method
Just changed

<ListView dataSource={this.state.dataSource} renderRow={this.renderRow} style={styles.listView} />

to

return(<ListView dataSource={this.state.dataSource} renderRow={this.renderRow} style={styles.listView} />);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM