使用keyExtractor,仍然收到警告,提示我的物品没有钥匙

时间:2019-05-19 23:21:20

标签: reactjs react-native react-native-flatlist

我正在创建一个flatList,但仍然收到警告,提示我我的物品上没有钥匙。

我试图创建一个功能来分解道具。

我的渲染方法:

render() {
    return (
      <View>
        <FlatList
          data={this.props.matches}
          renderItem={({ item }) => (
            <ListItem
              title={`${item.deck} vs. ${item.opponentDeck}`}
              subtitle={item.record}
              keyExtractor={(item)=>item.time}
            />
          )}
        />
      </View>
    );
  }

this.props如下:

Matches:  Array [
  Object {
    "OTPGameOne": false,
    "OTPGameTwo": false,
    "deck": "Amulet",
    "gameLosses": 0,
    "gameWins": 2,
    "opponentDeck": "Esper",
    "time": "04/26 3:08 p.m.",
    "winGameOne": true,
    "winGameTwo": true,
    "winMatch": true,
  }
  ...
],
Headings:  Array [
  "Deck",
  "Opp Deck",
  "Win Match",
  "Time/Date",
]

1 个答案:

答案 0 :(得分:1)

keyExtractor应该在平面列表上,而不在renderItem上

<FlatList
  data={this.props.matches}
  keyExtractor={(item)=>item.time}
  renderItem={({ item }) => (
    <ListItem
      title={`${item.deck} vs. ${item.opponentDeck}`}
      subtitle={item.record}/>
  )}
/>