javascript - Retrieve clicked array item on React Component -
i have search component outputs values array resultitem child component, every child component has button onclick property on it. bound function button value of array item clicked.
what have working every time clicked on every single resultitem button values of 0,1,2,3,4,5,6 individually perfect dont need array indexes need values of indexes
class resultitem extends component { constructor(props) { super(props); this.handleclick = this.handleclick } handleclick(index) { // index = this.props.applications[0] // index = this.props.applications.map(obj => obj.videoid[0]) console.log('this click', index) } render() { // console.log ('myprops', this.props.applications[0]); const {applications} = this.props; return ( <div> { applications.map((app, k) => { return ( <card key={k} style={styles.appcard}> <cardmedia style={styles.appmedia}> <div> <drafts color={white} style={styles.iconer}/> </div> </cardmedia> <cardtitle key={k} title={app.videoid} subtitle="application"/> {/* <div key={k}><h3>{app}</h3></div> */} <cardtext> <div> <div>status: <b>test</b> </div> </div> </cardtext> <floatingactionbutton style={styles.addbutton} backgroundcolor={'#cc0000'} onclick={this.handleclick.bind(this, k)} > <contentadd/> </floatingactionbutton> </card> ) }) } </div> ); } }
what i've tried far:
if use:
index = this.props.applications[0]
i first value of array on all buttons click on and
if use:
index = this.props.applications.map(obj => obj.videoid[0])
i first letter of every single item of array inside array on every click, there way can the value of element i've clicked on , if how?
index = this.props.applications[index]
or
index = this.props.applications[index].videoid
Comments
Post a Comment