android - 警告 : Empty section headers will be rendered - React Native

标签 android react-native react-native-listview

我正在通过从 API 获取书籍详细信息来制作一个简单的 ListView。该应用程序运行良好,但我收到警告和一些引用错误。你可以看看错误here 。我还提供了下面的代码。

index.android.js 代码:

import React, {Component} from 'react';
import {StyleSheet,Image,View,ListView,AppRegistry} from 'react-native';
import BookItem from './BookItem.js';


class dhrumil extends Component{


constructor(){
  super();
    var ds = new ListView.DataSource({rowHasChanged: (r1,r2) => r1!==r2});
  this.state={
    dataSource: ds.cloneWithRows([])
  }
}


componentDidMount(){
fetch('http://api.nytimes.com/svc/books/v3/lists/hardcover-fiction?response-format=json&api-key=73b19491b83909c7e07016f4bb4644f9:2:60667290')
.then((response) => response.json())
.then((rjson) => {
this.setState({
  dataSource: ds.cloneWithRows(rjson.results.books)
});
})
.catch((error)=>{
  console.warn(error);
});
}


render(){
  return(
<ListView style={styles.container}
dataSource= {this.state.dataSource}
renderRow={(rowData)=> {
return <BookItem style={styles.row}
coverURL={rowData.book_image}
title={rowData.title}
author={rowData.author}
/>;
}
}
/>

);
}


}
var styles = StyleSheet.create({
container: {
flex: 1,

backgroundColor: '#FFFFFF',
paddingTop: 24
},
row: {
flex: 1,
height: 44,
fontSize: 24,
padding: 42,
borderWidth: 1,
borderColor: '#DDDDDD'
}
});


AppRegistry.registerComponent('dhrumil',()=> dhrumil);

BookItem.js 代码:

import React,{Component} from 'react';
import {StyleSheet,View,Text,Image,AppRegistry} from 'react-native';

class BookItem extends Component{
propTypes:{
  coverURL: React.PropTypes.string.isRequired,
  author: React.PropTypes.string.isRequired,
  title: React.PropTypes.string.isRequired
}

render(){
return(
<View style={styles.bookItem}>
<Image style={styles.cover} source={this.props.coverURL}/>
<View style={styles.info}>
<Text style={styles.author}>{this.props.author}</Text>
<Text style={styles.title}>{this.props.title}</Text>
</View>
</View>
  );
}


}
var styles = StyleSheet.create({
  bookItem:{
    flex: 1,
    flexDirection: 'row',
    backgroundColor: '#FFFFFF',
    borderBottomColor: '#AAAAAA',
    borderBottomWidth: 2,
  },
  cover:{
    flex: 1,
    height: 150,
    resizeMode: 'contain'
  },
  info:{
    flex: 3,
    alignItems: 'flex-end',
    flexDirection: 'column',
    alignSelf: 'center',
    padding: 20
  },
  author:{
    fontSize: 18
  },
  title:{
    fontSize: 18,
    fontWeight: 'bold'
  }
});
AppRegistry.registerComponent("BookItem",()=> BookItem);

可能出现什么问题以及如何解决?

最佳答案

好吧,警告已经说明了一切。只需将enableEmptySections 添加到您的 ListView 组件中,警告就会消失。

关于android - 警告 : Empty section headers will be rendered - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44480929/

相关文章:

java - 我目前正在为最后一年开发一个应用程序。没有出现错误,但是当我选择我的 searchScreen 应用程序崩溃

android - React-native - npm-start 不工作 - 地铁出错 - events.js :183 throw er

react-native - 如何在 react-native 中执行水平 ListView 或 FlatList

java - 读取隐藏的 zip 文件

android - 如何设置 GNUMAKE 变量以使 ndk-build 正常工作

android - 阅读短信不起作用

javascript - 在函数内部调用函数,只有在函数结束后,其余的代码才会发生

android - 基本的 react native 应用程序不显示任何文本,仅在模拟器上显示带有应用程序名称的白屏

reactjs - Flatlist onEndReached 无限循环

具有动态行和列的 react native 平面列表