简体   繁体   中英

Returns [Object object] instead Dom string in Reactjs

var content = "";
for(var i=0;i<menuData.length;i++){           

 content += <li className={"accordion-menu-item "+showComponent} onClick={this.handleClick} id={menuTag}> 
     <div className={"menuLabel "+labelClassName}>{componentLabel}{manageActionLabel}</div>
     {allowDropDownElement}
     {this.createInnerComponent(allowDropDownFlag,innerComponents,showComponent)}
  </li>
}
return  <ul className="accordion-menu-wrapper">{content}</ul>

Above code is all put up in Reactjs. The above code is a code inside a function which is suppose to return the DOM string instead it return as [object object][object object][object object][object object]. Please help in solving this.

Instead of using content as a string use an array.

var content = [];
for(var i=0;i<menuData.length;i++){           

 content.push(<li className={"accordion-menu-item "+showComponent} onClick={this.handleClick} id={menuTag}> 
     <div className={"menuLabel "+labelClassName}>{componentLabel}{manageActionLabel}</div>
     {allowDropDownElement}
     {this.createInnerComponent(allowDropDownFlag,innerComponents,showComponent)}
  </li>);
}

return  <ul className="accordion-menu-wrapper">{content}</ul>

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM