javascript - Return multiple <td> from map without wrapping them within an enclosed tag -
i sort of stuck in case. know solve kind of errors have wrap them inside container or something. in case can't. please let me know if there solution this.
<div classname="table-responsive col-lg-12"> <table classname="table table-bordered table-hover"> <thead> <tr classname="active"> <th classname="width10">name</th> <th classname="width10">number</th> <th classname="width12">email</th> <th classname="width10">user handle</th> <th classname="width12">address</th> <th classname="width10">device imei</th> <th classname="width10">mapped date</th> </tr> </thead> { this.state.userdetails.map((user,i)=>{ return( <tbody key={i}> <tr> <td>{user.fn ? user.fn : "-"}</td> <td>{user.mob ? user.mob : "-"}</td> <td>{user.eml ? user.eml : "na"}</td> <td>{user.uh ? user.uh : "-"}</td> <td>{user.add ? user.add : "-"}</td> {this.state.devicedetails.map((dev,i)=>{ if(user.idx == dev.uid){ return( <td>{dev.imei ? dev.imei : "-"}</td> <td>{dev.dm ? dev.dm : "-"}</td> ) } })} </tr> </tbody> ) }) } </table> </div> above table want render. there 2 arrays have show table content. have perform mapping twice both different arrays. when map this.state.userdetails got error. if wrap inside <div> or <tr> both content placed in device imei <th>. how can solve this? appreciated.. :)
wrapping content jsx sugar should work. don't need flatten resulting array, react you. see jsx docs:
{this.state.devicedetails.map((dev,i)=>{ if(user.idx == dev.uid){ return([ <td>{dev.imei ? dev.imei : "-"}</td>, <td>{dev.dm ? dev.dm : "-"}</td> ]) } })} see this issue raised on react github page.
Comments
Post a Comment