如何从响应本机的单击事件中获取节点?

时间:2018-04-18 19:02:16

标签: javascript reactjs react-native

我从我的onPress处理程序接收事件,但我没有得到节点信息。我需要获取节点,以便我可以将它与另一个节点进行比较,以查看它是否与被点击的内容相同。怎么能在本地做出反应?

    getNodeInfo(e) {
        console.log('e: ', e)
    }

    render() {
        return (
            <TouchableWithoutFeedback ref={node => this.node = node} onPress={(e) => this.getNodeInfo(e)} style={{zIndex: 0}}>
                <View style={styles.wrapper}>
                    <ScrollView style={styles.scrollView}>
                        <ProductsContainer data={{productsList: { results: products }}}/>
                    </ScrollView>
                    <SearchBar style={styles.searchBar}/>
                </View>
            </TouchableWithoutFeedback>
        );
    }

2 个答案:

答案 0 :(得分:0)

您可以访问nativeEvent

中提到的以下道具的访问权限

要获取target: The node id of the element receiving the touch event,您可以简单记录

getNodeInfo(e) {
        console.log('e: ', e.nativeEvent.target)
    }

答案 1 :(得分:0)

constructor(){
  this.state = {..}
  this.getNodeInfo = this.getNodeInfo.bind(this);
} 
getNodeInfo(){
  console.log(this.node)
}