我正在構建一個反應應用程序。我有一個狀態數組,其中包含博客數組。 我使用BlogDisplay組件呈現每個博客。 以下是我的代碼:ReactJS - 傳遞一個對象數組的元素作爲道具
render() {
for(var i = 0;i < this.state.blogData.length;i++){
blogDataToRender.push(<BlogDisplay blogData = {this.state.blogData[i]} onUserTriggerForDetailedView ={this.props.onUserTriggerForDetailedView}/>);
}
return (
<div>
{blogDataToRender}
</div>
);
}
我得到這樣的警告:
index.js:5279 Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `BloggerHome`. See https://facebook.github.io/react/docs/lists-and-keys.html#keys for more information.
in BlogDisplay (created by BloggerHome)
in BloggerHome (created by Blogger)
in div (created by Blogger)
in div (created by Blogger)
in Blogger
是我的模型是否正確?我該如何解決這個問題?
非常感謝。
我試過了,但是不成功。可能是因爲我的新手知識。你能提供一個代碼示例嗎? – Varbi