在带有Native Base的React Native中具有相同密钥的两个孩子

如何解决以下错误:警告:遇到两个具有相同密钥 this.player = player => { const pos = interpolate(player.position,player.movementVector) resetDivSets() calcViewMatrix() mat4Translate(viewMatrix,-pos.x * glScale,-3.1 * glScale,pos.y * glScale) mat4RotateY(viewMatrix,playerRotation(player,player.drawMovementVector)) gl.uniformMatrix4fv(uVmatrix,false,viewMatrix) gl.uniform3f(uAmbientColor,1,1) gl.drawElements(gl.TRIANGLES,builtSprites.player.ibCount,gl.UNSIGNED_SHORT,builtSprites.player.ibStart * 2) // compute a clipspace position var clipspace = WHAT TO HAVE HERE??; // divide X and Y by W just like the GPU does. clipspace[0] /= clipspace[3]; clipspace[1] /= clipspace[3]; // convert from clipspace to pixels var pixelX = (clipspace[0] * 0.5 + 0.5) * gl.canvas.width; var pixelY = (clipspace[1] * -0.5 + 0.5) * gl.canvas.height; addDivSet("Player Name under player object",pixelX,pixelY); 的孩子。密钥应该是唯一的,以便组件在更新过程中保持其身份。非唯一键可能会导致子代重复和/或被忽略-这种行为不受支持,并且可能在将来的版本中更改。

那是我的清单:

[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>

这就是我的keyExtractor方法:

   /* 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)/ */
kangxiao248789 回答:在带有Native Base的React Native中具有相同密钥的两个孩子

您要将Arr=[ [8,5],[0,7,9] ] 绑定到keyExtractor函数,因此它将提供this对象作为第一个参数(在这里将其称为this)。因此,返回值将始终是Object的字符串表示形式( = [Object object]

简单的解决方案是只声明index而没有任何绑定。

,

对于FlatList代码

<List style={custom.PartList}>
     <FlatList extraData={this.state} data={this.state.data}
    keyExtractor={(item,index) => index.toString()}
 renderItem={this._renderItem.bind(this)} />
</List>
本文链接:https://www.f2er.com/3161031.html

大家都在问