Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何解决平面列表中的键问题_Javascript_Reactjs_React Native_React Native Flatlist_Flatlist - Fatal编程技术网

Javascript 如何解决平面列表中的键问题

Javascript 如何解决平面列表中的键问题,javascript,reactjs,react-native,react-native-flatlist,flatlist,Javascript,Reactjs,React Native,React Native Flatlist,Flatlist,这是我第一次接触React, 我的程序中有这个问题。你能帮我吗? 我在应用程序中使用TMDB API index.js:1 Warning: Encountered two children with the same key, `.$106242`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be d

这是我第一次接触React, 我的程序中有这个问题。你能帮我吗? 我在应用程序中使用TMDB API

index.js:1 Warning: Encountered two children with the same key, `.$106242`. Keys should be unique so that components maintain their identity across updates. Non-unique keys may cause children to be duplicated and/or omitted — the behavior is unsupported and could change in a future version.
        in div (created by View)
        in View (created by ScrollView)
        in div (created by View)
        in View (created by ForwardRef)
        in ForwardRef (created by ScrollView)
        in ScrollView (created by VirtualizedList)
        in VirtualizedList (created by FlatList)
        in FlatList (at Search.js:71)
        in div (created by View)
        in View (at Search.js:65)
        in Search (at App.js:8)
        in App (created by ExpoRootComponent)
        in ExpoRootComponent (created by RootComponent)
        in RootComponent
        in div (created by View)
        in View (created by AppContainer)
        in div (created by View)
        in View (created by AppContainer)
        in AppContainer
item.id.toString()}
renderItem={({item})=>}
onEndReachedThreshold={0.5}
onEndReachedThreshold={0.5}
onEndReached={()=>{
如果(this.page

任何命题

将平面列表代码更改为

<FlatList
    data = {this.state.films}
    keyExtractor = {(item, index) => index+"_"+item.id.toString() }
    renderItem={({item}) => <Text> <FilmItem film={item} /> </Text>}
    onEndReachedThreshold={0.5}
    onEndReachedThreshold={0.5}
    onEndReached={() => {
        if (this.page < this.totalPages) { // On vérifie qu'on n'a pas atteint la fin de la pagination (totalPages) avant de charger plus d'éléments
            this._loadFilms()
        }
    }}
/>
index+“”+item.id.toString()}
renderItem={({item})=>}
onEndReachedThreshold={0.5}
onEndReachedThreshold={0.5}
onEndReached={()=>{
如果(this.page
对于keyExtractor,您可以使用索引或索引与胶片的任何属性的组合。在下面的例子中,我使用了索引,并在同一行添加了注释,这也可以用来代替索引

index}/`${item.id.toString()}-${index}`
renderItem={({item})=>}
onEndReachedThreshold={0.5}
onEndReachedThreshold={0.5}
onEndReached={()=>{
如果(this.page

请清楚地说明您的问题。你想要实现什么?到目前为止,您尝试了什么?state.films数组应该包含id属性的唯一值,如果不是,您可以尝试其他唯一属性或索引。您的数组中有一些数据具有重复的
id
属性。修复数据或在兄弟姐妹中选择更好、更独特的属性。
<FlatList
    data = {this.state.films}
    keyExtractor = {(item, index) => index+"_"+item.id.toString() }
    renderItem={({item}) => <Text> <FilmItem film={item} /> </Text>}
    onEndReachedThreshold={0.5}
    onEndReachedThreshold={0.5}
    onEndReached={() => {
        if (this.page < this.totalPages) { // On vérifie qu'on n'a pas atteint la fin de la pagination (totalPages) avant de charger plus d'éléments
            this._loadFilms()
        }
    }}
/>
<FlatList
    data = {this.state.films}
    keyExtractor = {(item, index) => index } // `${item.id.toString()}-${index}`
    renderItem={({item}) => <Text> <FilmItem film={item} /> </Text>}
    onEndReachedThreshold={0.5}
    onEndReachedThreshold={0.5}
    onEndReached={() => {
        if (this.page < this.totalPages) { // On vérifie qu'on n'a pas atteint la fin de la pagination (totalPages) avant de charger plus d'éléments
            this._loadFilms()
        }
    }}
/>