【发布时间】:2021-02-09 21:36:57
【问题描述】:
我真的很难理解以下反应函数中的语法有什么问题
const listItem = (parentId) => {
var childCategories = categories.filter(category => category.ParentId === parentId)
return (
childCategories.map(category => (
<ListItem key={category.Id} button>
<ListItemText primary={category.Name} />
</ListItem>
listItem(category.Id) //// it doesn't like this line
))
)
}
如果我取出带有注释“//// 它不喜欢这一行”的行,则该函数可以正常工作,当然没有递归。我尝试了所有不同的 {} 和 () 组合,例如{listItem(category.Id)} 但它仍然不起作用。知道语法有什么问题。
【问题讨论】:
-
您能否在问题中包含整个组件?
标签: reactjs