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

标签 javascript reactjs

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

相关文章:

javascript - 无法清除设置间隔功能

javascript - 在不更新/修改该对象的情况下如何更新对象值?

javascript - 解析 NodeJS CSS 子包?

javascript - 获取WebView Android中的事件点击组件

javascript - 动态 block - 如何在保存/加载后创建动态样式表

reactjs - 如何在 react 中将选择框的值重置为默认值

javascript - 如何删除重复结果并合并在 mySQL 查询中具有相似属性的对象?

javascript - 如何使用 native react 在另一个屏幕上发送并显示文本输入的值?

javascript - 我如何使用具有异步/等待功能的守夜人?

javascript - React - 动态添加输入而不改变状态