I know I can write a function in Swipeout like this
var swipeButton = [{
text:'delete',
type:'delete',
onPress: function(){ alert('button pressed') }
}]
But I have a function named removeItem
, it gets a rowID from ListView. I think, maybe I can write in onPress like this:
onPress: () => this.props.removeItem(rowID)
The props removeItem
has been transmitted to the component which includes the 'Swipeout' part. But it did not work, so I want to know how I should correct my code.
When using arrow functions, the this
keyword doesn't work like you'd expect from normal functions. It points to the context of the lexical scope. This should work:
onPress: function () { this.props.removeItem(rowID) }
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.