2017-08-10 91 views
0

我們正在使用Flatlist開發反應本機應用程序。綁定數據來自API服務&其工作正常。假設沒有可用的數據,我們需要爲此顯示單獨的設計。Flatlist React Native - 無數據顯示

我們使用「renderEmptyListComponent」爲

共享代碼,請

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

請指導我如何才能做到這一點?

+0

有沒有這樣的道具「renderEmptyListComponent」。根據文檔,它是 「ListEmptyComponent」。 http://facebook.github.io/react-native/releases/0.47/docs/flatlist.html#flatlist – Dev

回答

1

可能要改用這一點:

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

或者如果也不起作用做舊三元JSX-eroo

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

希望這有助於