代码之家  ›  专栏  ›  技术社区  ›  Nikola Lukic

没有来自数组的渲染元素-ReactJS

  •  0
  • Nikola Lukic  · 技术社区  · 6 年前

    基于Typescript和ReactJS的项目。

    这是渲染代码:

    return (
                <div ref={this.myRef} style={this.state.myStyle} >
                  {this.state.sections.map((sectionsItem: AppI.SectionI) => {
                    if (this.state.activeSection === sectionsItem.name) {
                      console.log("TEST :", sectionsItem.elements );
                      sectionsItem.elements.map((element: React.ReactElement<any>, index: number) => {
                        return <span key={index} >{element}</span>;
                      });
                    }
                  })}
                </div>
               );
    

    在调试器中,我可以看到“elements”不是空的,但它不会在html中呈现。

    有什么建议吗?!

    1 回复  |  直到 6 年前
        1
  •  1
  •   codeepic zetriks    6 年前

    return 声明: 更改: sectionsItem.elements.map return sectionsItem.elements.map 你的内心 .map .地图

    return (
            <div ref={this.myRef} style={this.state.myStyle} >
              {this.state.sections.map((sectionsItem: AppI.SectionI) => {
                if (this.state.activeSection === sectionsItem.name) {
                  console.log("TEST :", sectionsItem.elements );
                  return sectionsItem.elements.map((element: React.ReactElement<any>, index: number) => {
                    return <span key={index} >{element}</span>;
                  });
                }
              })}
            </div>
           );