react-native flatlist - keyExtractor返回重复项并跳转到数据数组的末尾

时间:2018-05-21 09:37:25

标签: react-native react-native-flatlist

在这里报告奇怪的行为,希望有人遇到过这种情况。我收到错误"不变违规:VirtualizedList包含一个单元,该单元本身包含多个与父列表方向相同的VirtualizedList。您必须将唯一的listKey prop传递给每个兄弟列表。"

使用react native 0.55.4

return (
        <View style={{ flex: 1 }}>
            <FlatList
                data={data}
                keyExtractor={(item, index) => {
                    console.log(`${item}-${index}`)
                    return `${item}-${index}`;
                }}
                renderItem={this.renderItem}
                getItemLayout={this.getItemLayout}
                ItemSeparatorComponent={HairSpacer}
            />
        </View>
    );

数据:

["korbit", "kraken", "bitstamp", "bitflyer", "bittrex", "bitfinex", "poloniex", "huobi", "zaif", "coincheck", "bithumb", "coinnest", "btcbox", "okcoin", "aex", "binance", "coinbase", "coinrail", "upbit", "coinone", "kucoin", "gate", "zb", "coin", "gopax"]

控制台:

kraken-1 
bitstamp-2 
bitflyer-3 
bittrex-4 
bitfinex-5 
poloniex-6 
huobi-7 
zaif-8 
coincheck-9 
coincheck-9 
gopax-24 

我假设因为这个重复的列表项而抛出错误,尽管从数据支持中你可以看到它实际上并不重复。

欢迎任何建议

1 个答案:

答案 0 :(得分:0)

尝试使用listkey代替keyExtractor