我想输出 ReactJs 中每个帖子的所有问题的数量。为此,我创建了下一个代码:
const posts = [{
title: 1,
id: "123"
},
{
title: 2,
id: "1234"
},
{
title: 3,
id: "12345"
}
]
const questions = [{
id: 55,
name: 'question one',
id_post: '123'
},
{
id: 56,
name: 'question two',
id_post: '123'
},
{
id: 57,
name: 'question three',
id_post: '1234'
},
{
id: 58,
name: 'question four',
id_post: '123'
},
];
posts.map( (e, k) => {
return (
<Link key={k} to={`demo/${e.id}/url`}>
{ questions.filter(here i want to output the number of questions that correspond to each post)}
</Link>
)
})
我有posts
数组和questions
数组。我想Link
在 url 中创建一个它自己的 id,同时过滤每个帖子的问题数量,并在里面Link
输出数字。对此怎么办?
...接下来的问题是:我正在使用蚂蚁设计、表格组件,然后我可以使用下一个结构:
` render: ()=>(
console.log('render'),
events.map( (e, key) => {
console.log(ev.id);
return (
<Link key={k} to={`demo/${e.id}/url`}>
{ questions.filter(q => q.id_post === e.id).length }
</Link>
)
)
})
I use this to create a column in my table. The problem is that i have to many renders. When i put this code i get all ids in
console.log(ev.id) on each render. And at the end i get for example not
0 as length but
00000000`,取决于但我有多少渲染或 ID。如何解决这个问题?请看一看:45 https://codesandbox.io/s/8i1dy