Javascript _这个函数不是一个函数
我在react native上工作,出现以下错误: _此6.callGeocodage不是一个函数 我的代码:Javascript _这个函数不是一个函数,javascript,react-native,Javascript,React Native,我在react native上工作,出现以下错误: _此6.callGeocodage不是一个函数 我的代码: callGeocodage(adress) { console.log(adress); } renderAd(item, index) { return ( <Card style={{ elevation: 3, width: Dimensions.get('window').width}}> <CardItem c
callGeocodage(adress) {
console.log(adress);
}
renderAd(item, index) {
return (
<Card style={{ elevation: 3, width: Dimensions.get('window').width}}>
<CardItem cardBody>
<TouchableOpacity onPress={() => {this.callGeocodage(item.adress)}}>
<IconFontAwesome name={ICON_SEARCH} />
</TouchableOpacity>
<Text>{item.adress} </Text>
</CardItem>
</Card>
);
}
有人知道为什么吗???您必须将此绑定到构造函数中的renderAd:
constructor(props){
super(props);
this.renderAd = this.renderAd.bind(this);
}
或将其用作箭头函数:
const renderAd = (item, index) => {
尝试在构造函数中绑定callGeocodage函数,如下所示。callGeocodage=this.callGeocodage.bindthis;按如下方式编写函数:callGeocodage=address=>{console.logaddress;};请告诉我们renderAd是怎样的called@MartinShishkov不,问题不是它没有绑定,而是找不到它。我尝试使用renderAd=item,index=>{,没关系,谢谢