Redux FlatList无法正确显示对象

时间:2018-11-14 07:26:49

标签: reactjs react-native redux react-redux

我正在将redux与react native一起使用,我有一个平面列表要显示,但不显示对象的标题或描述。它在屏幕上显示对象的所有行,但是例如当我调用标题时,它不会显示它。这是我的代码:

import React, {Component} from 'react';
import { FlatList,Text } from 'react-native';
import { connect } from 'react-redux';
import ListItem from './ListItem';

class LibraryList extends Component {

renderItem(library) {
  return <ListItem library={library} />;

}

  render() {
    return (
      <FlatList
        data={this.props.libraries}
        renderItem={this.renderItem}
        keyExtractor={library => library.id.toString()}
       />

    );
  }

}

const mapStateToProps = state => {
  return { libraries: state.libraries }
};

export default connect(mapStateToProps)(LibraryList);

ListItem.js

import React, { Component } from 'react';
import { Text } from 'react-native';
import { CardSection } from './common';

class ListItem extends Component{
  render() {
      return(
        <CardSection>
          <Text>
          {this.props.library.title}
          </Text>
        </CardSection>
      );
  }
}

export default ListItem;

1 个答案:

答案 0 :(得分:0)

尝试通过仅在参数中放置花括号并在其中的示例中指定库对象来修改renderItem函数

`

_renderItem = ({item}) => (
    <MyListItem
      id={item.id}
      onPressItem={this._onPressItem}
      selected={!!this.state.selected.get(item.id)}
      title={item.title}
    />
  ); `