首页 > 使用react递归,报render方法错误

使用react递归,报render方法错误

控制台报错

invariant.js?4599:39 Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of `Department`

Department中的render

    render(){
        // const style={
        //     display:none
        // }
        const currentDepartment = this.props.currentDepartment;
        // debugger;
        const departList = this.props.departList;
        const userList = this.props.userList;
        let getDepartData = this.props.getDepartData;
        const _this = this;
        debugger;
        const list = getDepartData.call(_this, currentDepartment, departList, userList);

        return (
            <div>
                <button></button>
                <h5>{this.props.currentDepartment.D_NAME}</h5>
                <ul>
                    {list}
                </ul>
            </div>
        )
    }

调用render的递归

      departList = departments.map(function(item){
        if(department.SHOW_ID == item.D_PARENTID_SHOW_ID){
          return
            (<Department
                  getCurrentDepartData={this.props.getCurrentDepartData}
                  currentDepartment={item}
                  departList={departments}
                  userList={users}
                  getDepartData={this.props.getDepartData}
                  key={item.SHOW_ID} />)
        }
      })

“Department中的render”里面的{list}不能直接这么用。list是一个object的数组,react不知道怎么把object转成响应的HTML,你得告诉它,应该

{list.map(item => {
    return "替换成HTML"
})}
【热门文章】
【热门文章】