reactjs - creating elements through loop inside render function in react -
this.state.obj= [{"listing_id":"1","listing_name":"a"},{"listing_id":"2","listing_name":"iima "},{"listing_id":"3","listing_name":"dsffgdf"}];
inside render function =>
{this.state.obj.map((name,index) => <tr key={index}> <td key={index} onclick={this.openoptions.bind(this,name.listing_id)}>{name.listing_id}</td> <td key={name.listing_name}>{name.listing_name}</td> if(name.listing_id == openoptionsvar){ <td key={index+1} >edit</td> } </tr> )}
i want display last td element if openoptionsvar value equals listing_id of row??
listing_id
react.proptypes.string. check proptype openoptionsvar (probably react.proptypes.number). afraid different properties have convert of them correspondent proptype , in condition use strict equality comparison, doing example (if openoptionsvar number):
if(number(name.listing_id) === openoptionsvar){ <td key={index+1} >edit</td> }
Comments
Post a Comment