Saturday, May 11, 2024
67
rated 0 times [  74] [ 7]  / answers: 1 / hits: 57970  / 9 Years ago, tue, september 1, 2015, 12:00:00

Hi this is my first time developing apps in javascript and react-native, its kind of a noob question. How do I call _getData function in __onRegionChangeComplete function? I tried this._getData() it shows




error: undefined is not a function(evaluation'this._getData()')').




var React = require('react-native');

var {
StyleSheet,
Text,
View,
Image,
MapView,
Component,
} = React;

class Map extends Component {
render() {
return (
<View style={styles.container}>
<MapView style={styles.map}
showsUserLocation={true}
onRegionChangeComplete={this._onRegionChangeComplete}
/>
</View>
);
}

_onRegionChangeComplete(region)
{

}

_getData()
{

}
}

var styles = StyleSheet.create({
container:{
flex: 1
},
map: {
flex: 1,
},
image: {
width: 64,
height: 64
}
});

module.exports = Map;

More From » react-native

 Answers
2

Solve it by changing the extends Component to createclass and adding commas after each function. read a brief introduction about them is that createclass have autobinding for function and extends component does not do that for you, so you have to bind them yourself.



var React = require('react-native');

var {
StyleSheet,
Text,
View,
Image,
MapView,
Component,
} = React;

var Map = React.createClass({
render(){
return (
<View style={styles.container}>
<MapView style={styles.map}
showsUserLocation={true}
rotateEnabled={false}
onRegionChangeComplete={this.onRegionChangeComplete}
/>
</View>
);
},

onRegionChangeComplete(region) {
this.getData(region)
},

getData(region) {

},
});

var styles = StyleSheet.create({
container:{
flex: 1
},
map: {
flex: 1,
},
image: {
width: 64,
height: 64
}
});

module.exports = Map;

[#65231] Saturday, August 29, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sashacitlallik

Total Points: 30
Total Questions: 100
Total Answers: 85

Location: Belarus
Member since Tue, Mar 14, 2023
1 Year ago
sashacitlallik questions
Tue, Jun 16, 20, 00:00, 4 Years ago
Thu, Feb 20, 20, 00:00, 4 Years ago
Mon, Nov 25, 19, 00:00, 5 Years ago
;