React native React Native:数组中的每个子级都应该有唯一的键,即使我包含了该键
我刚开始使用React native React Native:数组中的每个子级都应该有唯一的键,即使我包含了该键,react-native,React Native,我刚开始使用React Native,在处理数组的map时遇到了一个问题。因为它需要为所有元素提供一个唯一的键。 我已经在render方法中指定了键,但仍然收到警告。 这是密码 import React, { Component } from 'react'; import {Text , ScrollView} from 'react-native'; import axios from 'axios'; import AlbumDetail from './AlbumDetail' expo
React Native
,在处理数组的map
时遇到了一个问题。因为它需要为所有元素提供一个唯一的键。
我已经在render方法中指定了键,但仍然收到警告。
这是密码
import React, { Component } from 'react';
import {Text , ScrollView} from 'react-native';
import axios from 'axios';
import AlbumDetail from './AlbumDetail'
export default class AlbumList extends Component {
state = {albums: ['Fetching Data...']};
componentWillMount() {
console.log('fetching data');
// Make a request
axios.get('http://rallycoding.herokuapp.com/api/music_albums')
.then(response => this.setState({albums: response.data}));
}
renderAlbums() {
return this.state.albums.map(album =>
<AlbumDetail
key = {album.title}
album = {album}
/>
);
}
render() {
return(
<ScrollView>
{this.renderAlbums()}
</ScrollView>
);
}
}
看看你的错误。它说错误在AlbumList的呈现调用中。您指定的代码很好 看看你的错误。它说错误在AlbumList的呈现调用中。您指定的代码很好 有解决办法吗?有解决办法吗?
ExceptionsManager.js:73 Warning: Each child in an array or iterator should have a unique "key" prop.
Check the render method of `AlbumList`. See https://fb. me/react-warning-keys for more information.
in AlbumDetail (at AlbumList.js:16)
in AlbumList (at index.js:21)
in RCTView (at View.js:113)
in View (at index.js:19)
in FirstApp (at renderApplication.js:35)
in RCTView (at View.js:113)
in View (at AppContainer.js:102)
in RCTView (at View.js:113)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:34)