Flatlist React Native - No Data Display

断了今生、忘了曾经 提交于 2019-12-24 08:23:48

问题


We are developing a react native application using Flatlist. Binding data from API service & its working fine. Suppose no data available in service we need to display separate design for that.

We are using "renderEmptyListComponent" for that

sharing the code, please check

<FlatList style={{ backgroundColor: 'white' }}
              data={this.state.dataSource}
              renderItem={({ item }) => (this.renderMovie(item))}
              keyExtractor={item => item.salesID}
              renderEmptyListComponent= {this.noItemDisplay}
              ItemSeparatorComponent={this.renderSeparator}>
            </FlatList>

please guide me how can we do this?


回答1:


might want to use this instead:

<FlatList 
  style={{ backgroundColor: 'white' }}
  data={this.state.dataSource}
  renderItem={({ item }) => (this.renderMovie(item))}
  keyExtractor={item => item.salesID}
  ListEmptyComponent={this.noItemDisplay}
  ItemSeparatorComponent={this.renderSeparator}>
</FlatList>

Or if that also doesn't work do the old ternary jsx-eroo

{ this.data ? <FLatList /> : null }

Hope this helps



来源:https://stackoverflow.com/questions/45611180/flatlist-react-native-no-data-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!