gpt4 book ai didi

javascript - Return 未执行 - Javascript、React.js

转载 作者:行者123 更新时间:2023-11-30 08:22:25 24 4
gpt4 key购买 nike

我的函数有问题,在 if 语句中调用它后它有时会工作但它不会返回最后一个 return 它再次开始新值(value)。

这是我渲染的数据:

 listData: [
[
{id: 1, title: 'list1'},
{id: 2, title: 'list2'},
],
{id: 3, title: 'list3'},
];

和函数:

  isArray(a) {
return (!!a) && (a.constructor === Array);
}

renderList(item, options) {
if (this.isArray(item) === true) {
item.map((child, childIndex) => {
this.renderList(child, options)
})
}
return (
<List item={item} />
)
}

最佳答案

renderList(item, options) {
if ( Array.isArray(item) ) {
return item.map( (child, childIndex) => {
return this.renderList(child, options)
})
} else {
return (
<List item={item} />
)
}
}

关于javascript - Return 未执行 - Javascript、React.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51284480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com