如何摆脱此警告?如果我删除task.created
则没有警告。无法解决这个问题。请参阅下面的代码示例:
Warning: Any use of a keyed object should be wrapped in React.addons.createFragment(object) before being passed as a child.
ShowAllPosts = React.createClass({
mixins: [ReactMeteorData],
getMeteorData() {
// This function knows how to listen to Meteor's reactive data sources,
// such as collection queries
return {
// Returns an array with all items in the collection
tweets: Posts.find().fetch().reverse()
}
},
render() {
var showHTML = this.data.posts.map(function (task) {
return (
<div key={task._id}>
<img className="profile-pic" src="images/puppy.jpeg" />
{task.content}
<br />
Date: {task.created}, <a href="{task._id}">Get Link</a>, id: {task._id}
<hr />
</div>
);
});
return (
<ul>
<hr />
{/* Access the data from getMeteorData() on this.data */}
{ showHTML }
</ul>
);
}
});
答案 0 :(得分:1)
我假设task.created
是一个Date对象。
React不会自动将日期投射到字符串,因此您需要编写类似{task.created.toString()}
的内容或使用moment之类的包来格式化日期。