【问题标题】:When I read the firebase records, type error getting当我阅读 firebase 记录时,输入错误
【发布时间】:2020-05-18 15:25:25
【问题描述】:

我是 react 新手,我尝试读取 firebase 记录,但 rowHasChanged 方法似乎出错了;

typeerror: undefined 不是构造函数(评估 'new_raeactaive.FlatList.DataSoruce ({rowHasChanged:function rowHasChanged(r1, r2) { return r1 !==r2;}}))]

import _ from 'lodash';
import React, {
  Component
} from 'react';
import {
  View,
  FlatList
} from 'react-native';
import {
  connect
} from 'react-redux';
import {
  studentListData
} from '../actions/StudentAcitions';
import ListItem from './ListItem';

class Studentlist extends Component {
  UNSAFE_componentWillMount() {
    this.props.studentListData();
    this.createDataSource(this.props);
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    this.createDataSource(nextProps);
  }
  createDataSource({
    studentsArray
  }) {
    const ds = new FlatList.DataSource({
      rowHasChanged: (r1, r2) => r1 !== r2,
    });

    this.DataSource = ds.cloneWithRows(studentsArray);
  }
  renderRow(ogrenci) {
    return <ListItem ogrenci = {
      ogrenci
    }
    />;
  }
  render() {
    return ( <
      View >
      <
      FlatList data = {
        this.props.studentsArray
      }
      renderItem = {
        this.renderRow
      }
      keyExtractor = {
        (item, index) => index.toString()
      }
      /> <
      /View>
    );}
}

【问题讨论】:

  • createDataSource函数的作用是什么?
  • 我创建了这个函数 (createDataSource) 来设置 this.DataSource = ds.cloneWithRows(studentsArray);

标签: javascript arrays react-native react-redux


【解决方案1】:

FlatList 没有 ListView 的 DataSource 函数。尝试更改为 Listview 而不是 FlatList。您可以在下面的链接中看到带有 DataSource 的 ListView

https://reactnative.dev/docs/0.49/listview

注意: ListView 已弃用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2021-05-18
    • 2017-05-27
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    相关资源
    最近更新 更多