Reactjs 如何将用户连接到post in React?
如何将用户连接到他们的帖子?该帖子具有发布评论的用户id,但如何映射帖子 这是我的邮政地图Reactjs 如何将用户连接到post in React?,reactjs,mapping,connect,Reactjs,Mapping,Connect,如何将用户连接到他们的帖子?该帖子具有发布评论的用户id,但如何映射帖子 这是我的邮政地图 {post.map(post => ( <Post key={post.id} post={post} /> ))} 所以我有帖子列表和用户列表,它们是分开的 但是帖子有发布者的用户id,但是我如何连接他们呢? 通过post进行映射,并且当用户的用户ID与post过滤器的用户ID相等时,它还是什么? 我如何通过这种
{post.map(post => (
<Post key={post.id} post={post} />
))}
所以我有帖子列表和用户列表,它们是分开的
但是帖子有发布者的用户id,但是我如何连接他们呢?
通过post进行映射,并且当用户的用户ID与post过滤器的用户ID相等时,它还是什么?
我如何通过这种关系将他们联系起来
我想要的东西,但它给出了一个错误user.post是未定义的
{post.map(post => (
<Post
key={post.id}
food={post}
user={user.filter(
user =>
user.post.userid)}
/>
))}
{post.map(post=>(
user.post.userid)}
/>
))}
因为post有userid
和user有id
,所以您可以用如下方法解决它:
{post.map((post) => (
<Post
key={post.id}
food={post}
user={user.find((u) => u.id === post.userid)}
/>
))}
{post.map((post)=>(
u、 id==post.userid)}
/>
))}
因为post有userid
和user有id
,所以您可以用如下方法解决它:
{post.map((post) => (
<Post
key={post.id}
food={post}
user={user.find((u) => u.id === post.userid)}
/>
))}
{post.map((post)=>(
u、 id==post.userid)}
/>
))}
当我在post标签中为用户设置如下值时,它对我有效
<Post
key={post.id}
food={post}
user={users.find(
user =>
post.userid === user.id //if you have an users array here you should use find instead of filter and then try to match the post.userid with user.id.
)}
/>
post.userid===user.id//如果此处有用户数组,则应使用find而不是filter,然后尝试将post.userid与user.id匹配。
)}
/>
当我在post标签中为用户设置如下值时,它对我有效
<Post
key={post.id}
food={post}
user={users.find(
user =>
post.userid === user.id //if you have an users array here you should use find instead of filter and then try to match the post.userid with user.id.
)}
/>
post.userid===user.id//如果此处有用户数组,则应使用find而不是filter,然后尝试将post.userid与user.id匹配。
)}
/>