React native 警告:FlattChildren(…):遇到两个具有相同密钥的子项,

React native 警告:FlattChildren(…):遇到两个具有相同密钥的子项,,react-native,React Native,我收到以下错误警告:FlattChildren(…):遇到两个具有相同密钥的子项 使用React Native、listview时 这是我的密码 // Render the row for the list view _renderRow(rowData, sectionID, rowID, highlightRow) { return ( <TouchableHighlight underlayColor={'#ccc'} onPress=

我收到以下错误警告:FlattChildren(…):遇到两个具有相同密钥的子项

使用React Native、listview时

这是我的密码

// Render the row for the list view
    _renderRow(rowData, sectionID, rowID, highlightRow) {
        return (
            <TouchableHighlight underlayColor={'#ccc'} onPress={() => this._onPressProject({projectName:rowID.projectName, projectId:rowID.projectId})}>
                <View>
                    <View style={styles.row}>
                        <Text style={styles.text}>{rowID.projectName}</Text>
                    </View>
                </View>
            </TouchableHighlight>
        );
    }
//为列表视图呈现行
_renderRow(rowData、sectionID、rowID、highlightRow){
返回(
此._onPressProject({projectName:rowID.projectName,projectId:rowID.projectId})}>
{rowID.projectName}
);
}

您需要设置放入每行的组件的
键。
可能会使用您的
projectId
,如下所示:

_renderRow(rowData, sectionID, rowID, highlightRow) {
    return (
        <TouchableHighlight key={rowID.projectId} underlayColor={'#ccc'} onPress={() => this._onPressProject({projectName:rowID.projectName, projectId:rowID.projectId})}>
            <View>
                <View style={styles.row}>
                    <Text style={styles.text}>{rowID.projectName}</Text>
                </View>
            </View>
        </TouchableHighlight>
    );
}
\u renderRow(行数据、节ID、行ID、highlightRow){
返回(
此._onPressProject({projectName:rowID.projectName,projectId:rowID.projectId})}>
{rowID.projectName}
);
}

每当循环通过要渲染的某些元素时,都需要提供
键。每个
键都应该是唯一的

“键”是创建元素列表时需要包含的特殊字符串属性


您可以阅读有关

的更多信息,因此这与列表视图渲染行无关,但下面的JS代码并不确定我为什么能够将对象推入数组

for(j = 0; j < projectLength; j++) {
                project = projects[j];
                // Add Unique Row ID to RowID Array for Section
                rowIDs[i].push({proejctName:project.name. projectId:project.id});

                // Set Value for unique Section+Row Identifier that will be retrieved by getRowData
                dataBlob[company.id + ':' + project.id] = project;
            }

我这样做了,我尝试了TouchableHighlight和view,但文本仍然会出错
rowIDs[i].push(project.name + ':' + project.id);