ReactNative TypeError:undefined 不是一个对象(评估'Object.keys(dataBlob[sectionID])') [英] ReactNative TypeError: undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])')

查看:35
本文介绍了ReactNative TypeError:undefined 不是一个对象(评估'Object.keys(dataBlob[sectionID])')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am running the following code in iOS emulator but I am getting undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])') error. Please, could you help me to see what I am doing wrong?

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

this.state = { dataSource: this.ds.cloneWithRows(props.projects), <== ERROR POINT initialLoading: false, refreshing: false };

//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模拟器报错

=>> 错误按摩图像

推荐答案

我推荐使用这个库来StateManger由于某些原因首先,实现起来很简单第二,性能比Redux高这个 Lib React-Beep ==> 链接

I recommend using this library to StateManger for some reasons First, it's very simple to implement Second, it has high performance than Redux this Lib React-Beep ==> Link

这篇关于ReactNative TypeError:undefined 不是一个对象(评估'Object.keys(dataBlob[sectionID])')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆