ReactNative SectionList 缺少关键警告 [英] ReactNative SectionList Missing Key Warning
问题描述
我正在关注 SectionLists 上的 ReactNative 教程 (https://facebook.github.io/react-native/docs/using-a-listview.html#content) 并遇到警告消息.
I'm following the ReactNative tutorial on SectionLists (https://facebook.github.io/react-native/docs/using-a-listview.html#content) and have run into a warning message.
警告状态
"警告:VirtualizedSectionList:您提供的 section
缺少 key
属性.
"Warning: VirtualizedSectionList: A section
you supplied is missing the key
property.
VirtualizedList:缺少项的键,请确保为每个项指定键属性或提供自定义 keyExtractor"
"VirtualizedList: missing keys for items, make sure to specify a key property on each item or provide a custom keyExtractor"
有人可以协助解决此警告吗?
Can someone assist in resolving this warning?
编辑所以我能够通过向部分添加一个键来解决第一个警告
Edit So I was able to resolve the first warning by adding a key to the sections
sections={[
{key: 'D', title: 'D', data: ['Devin']},
{key: 'J', title: 'J', data: ['Jackson', 'James', 'Jillian', 'Jimmy', 'Joel', 'John', 'Julie']},
]}
但是我仍然收到 1 个实例的第二个错误.
But am stilling getting the second error for 1 instance.
推荐答案
我之前遇到过同样的错误.定义 keyExtractor 属性为我解决了这个问题.
I came across the same error before. Defining the keyExtractor property solved it for me.
https://facebook.github.io/react-native/docs/sectionlist.html#keyextractor
你试过了吗?
这篇关于ReactNative SectionList 缺少关键警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!