【发布时间】:2019-11-05 08:59:15
【问题描述】:
如何解决以下错误:警告:遇到两个孩子使用相同的密钥 [object Object]。密钥应该是唯一的,以便组件在更新时保持其身份。非唯一键可能会导致子项被重复和/或省略——这种行为不受支持,并且可能在未来的版本中发生变化。
这是我的清单:
<List style={custom.PartList}>
<FlatList extraData={this.state} data={this.state.data} keyExtractor={this._keyExtractor.bind(this)} renderItem={this._renderItem.bind(this)} />
</List>
这是我的列表项:
/* Render Item - Render One Row - Item - (Tool) */
_renderItem({ item }) {
const custom = styles(this.props);
return (
<View style={custom.PartView}>
<ListItem style={custom.PartListItem} onPress={() => this._handleRead(item.tool_id, item.tool_name, item.tool_description, item.tool_count, item.tool_availability)}>
<Image style={custom.PartImage} source={require('@app/assets/images/tools.png')}/>
<Text style={custom.PartName}>{item.tool_name}</Text>
</ListItem>
</View>
);
}
/* /Render Item - Render One Row - Item - (Tool)/ */
这就是我的 keyExtractor 方法:
/* Key Extractor Method - For Index Tools */
_keyExtractor(index) {
return index.toString();
}
/* /Key Extractor Method - For Index Tools/ */
【问题讨论】:
标签: javascript list react-native listitem native-base