我的函数有问题,在 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/