ReactNative TypeError:未定义不是对象(正在评估'Object.keys(dataBlob [sectionID])')

时间:2019-09-18 03:57:12

标签: react-redux

我在iOS模拟器中运行以下代码,但未定义不是对象(正在评估'Object.keys(dataBlob [sectionID])')错误。拜托,你能帮我看看我做错了什么吗?

this.state = {           数据源:this.ds.cloneWithRows(props.projects),<==错误点           initialLoading:否,           令人耳目一新:错误         };

//import liraries
import React, {Component} from 'react';
import {View, StyleSheet, Alert, ScrollView, RefreshControl, ListView, ActivityIndicator} from 'react-native';

import PropTypes from 'prop-types';
import ViewPropTypes from 'react-native';
import StatusBar from '../components/common/StatusBar';
import Header from '../components/common/Header';
import Subtitle from '../components/common/Subtitle';
import ProjectThumbnail from '../components/project/ProjectThumbnail';
import FilterButton from '../components/common/BottomButton';
import mockData from "../data/mockData";
import * as globalStyles from '../styles/global';

// create a component
export default class ProjectList extends Component {

  constructor(props) {
    super(props);
    this.ds = new ListView.DataSource({
      rowHasChanged: (row1, row2) => row1.title !== row2.title 
    });
    this.state = {
      dataSource: this.ds.cloneWithRows(props.projects), 
      initialLoading: false, 
      refreshing: false
    };

    console.log(this.state.dataSource);
    this.renderRow = this.renderRow.bind(this);
    this.refresh = this.refresh.bind(this); 

  }

  componentWillMount() { 
    this.refresh();
  }

  componentWillReceiveProps(nextProps) { 
    this.setState({
      dataSource: this.state.dataSource.cloneWithRows(nextProps.projects),
      initialLoading: false
    });
  }

  refresh() { 
    if (this.props.loadProjects) {
      this.props.loadProjects();
    }
  }

  renderRow(rowData, ...rest) { 
    const index = parseInt(rest[1], 10);
    return (
      <ProjectThumbnail
        style={styles.ProjectThumbnail}
        index={index}
        {...rowData} 
      />
    );
  }


  render() {
    const {
      listStyles = globalStyles.COMMON_STYLES.pageContainer,
      showLoadingSpinner
    } = this.props;
    const { initialLoading, refreshing, dataSource } = this.state;

    return (
      (initialLoading && showLoadingSpinner
        ? (
          <View style={[listStyles, styles.loadingContainer]}>
            <ActivityIndicator
              animating
              size="small"
              {...this.props}
            />
          </View>
        ) : (
          <View style={styles.container}>
            <StatusBar />
            <Header navigation={this.props.navigation} />
            <Subtitle subtitle="프로젝트" />
            <ListView
              refreshControl={
                <RefreshControl
                  refreshing={refreshing}
                  onRefresh={this.refresh}
                />
              }
              enableEmptySections 
              dataSource={dataSource} 
              renderRow={this.renderRow}
              style={listStyles}
            />
            
            <FilterButton
              title="필터 적용"
              IconName="ios-options"
              onPress={() => alert ('button Pressed')}
            />
          </View>
        )
      )
    );
  }
}

ProjectList.propTypes = {
  projects: PropTypes.arrayOf(PropTypes.object),
  listStyles: ViewPropTypes.style,
  loadProjects: PropTypes.func,
  showLoadingSpinner: PropTypes.bool 
};

ProjectList.defaultProps = {
  showLoadingSpinner: true 
};


const styles = StyleSheet.create ({
  ProjectThumbnail: {
    marginBottom: 20
  },
  container: {
    flex: 1,
  },
  loadingContainer: {
    alignItems: 'center',
    justifyContent: 'center'
  },

});

iOS仿真器的错误消息

= >> ERROR MASSAGE IMAGE

1 个答案:

答案 0 :(得分:0)

我建议将此库用于StateManger 由于某些原因 First,实现起来非常简单 Second,它比Redux具有更高的性能  这个库React-Beep ==> Link