I wrote a function called renderMyRow to render rows in a ListView, but I found it is strange that I can't get this in this function.
Then I fixed it by add a bind(this) in my code, but i wonder why i cannot get 'this' in my renderMyRow ?
here is the code
classSearchResultextendsComponent{constructor(props){super(props);vardataSource=newListView.DataSource({rowHasChanged: (r1,r2)=>r1.guid!==r2.guid});this.state={dataSource: dataSource.cloneWithRows(this.props.listings)};}render(){return(<ListViewdataSource={this.state.dataSource}renderRow={this.renderMyRow}/>)}rowPressed(propertyGuid){varproperty=this.props.listings.filter(prop=>prop.guid===propertyGuid)[0];this.props.navigator.push({title: 'Property',component: PropertyView,props: {property: property}})}renderMyRow(rowData,sectionID,rowID){console.log(this);// Output: nullvarprice=rowData.price_formatted.split(' ')[0];return(<TouchableHighlightunderlayColor='#DDDDDD'onPress={()=>this.rowPressed(rowData.guid)}><View><Viewstyle={styles.rowContainer}><Imagestyle={styles.thumb}source={{uri : rowData.img_url}}/><Viewstyle={styles.textContainer}><Textstyle={styles.price}>£{price}</Text><TextnumberOfLines={1}>{rowData.title}</Text></View></View><Viewstyle={styles.separator}/></View></TouchableHighlight>);}}
I wrote a function called
renderMyRowto render rows in aListView, but I found it is strange that I can't getthisin this function.Then I fixed it by add a
bind(this)in my code, but i wonder why i cannot get 'this' in myrenderMyRow?here is the code