【问题标题】:ReactNative TypeError: undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])')ReactNative TypeError:未定义不是对象(评估'Object.keys(dataBlob [sectionID])')
【发布时间】:2019-09-18 03:57:12
【问题描述】:

我在 iOS 模拟器中运行以下代码,但出现 undefined is not an object (evalating 'Object.keys(dataBlob[sectionID])') 错误。拜托,你能帮我看看我做错了什么吗?

this.state = { 数据源:this.ds.cloneWithRows(props.projects)

//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

【问题讨论】:

    标签: react-redux


    【解决方案1】:

    我推荐使用这个库来StateManger 由于某些原因 First,实现起来很简单 Second,性能比 Redux 高 这个 Lib React-Beep ==> Link

    【讨论】:

    • 欢迎您的 GoodLuk ;)
    猜你喜欢
    • 2016-09-29
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 2021-12-01
    • 2019-11-16
    • 2020-02-09
    • 2019-12-07
    相关资源
    最近更新 更多