javascript - 在渲染中获取数据,但是在显示时,什么都没有出现
问题描述
我在反应原生方面面临着一个大问题。我有一个 react-native-maps 和一些标记。我希望当您单击标记时,您会获得一些数据并将其显示在标记中。但是我能够获取数据,但是当我显示它时什么都没有显示。但是,在渲染函数中,当我执行 console.log 时,我可以看到我的显示,所以我不明白为什么数据存在于渲染中而不是返回中,这对我来说毫无意义,我尝试了一切。 ..
这是我的代码。如果有人可以帮助我,那就太好了。谢谢 :)
我只是放了一个随机的免费api给你看
export class CustomMarker extends Component {
constructor(props) {
super(props)
this.state = {
bonjour: ""
}
}
getData() {
axios.get('https://dog.ceo/api/breeds/image/random').then((data) => {
this.setState({ bonjour: data.data.message})
//console.log(this.state.bonjour)
})
}
render() {
console.log(this.state.bonjour)
return (
<Marker key={this.props.id} coordinate = {{latitude: Number(this.props.data.dLocLati), longitude: Number(this.props.data.dLocLongi)}}
pinColor = {"red"}
title={this.props.data.iVehId}
description={this.props.data.sLocStatus}
onPress={() => this.getData()
}
>
<Callout>
<View>
<Text>{this.state.bonjour}</Text>
</View>
</Callout>
</Marker>
)
}
}
解决方案
推荐阅读
- c# - 模型查询Mysql和EF6 c# windows窗体的错误
- bots - 我是一个新的 discord.py 用户,试图嵌入一个 8ball 命令
- delphi - 有什么方法可以将 String 变量转换为 Char
- python - 使用病毒总API时discordpy bot中的JSONDecodeError
- python - re.sub() 用于空格和制表符
- stored-procedures - Snowflake IF ELSE 存储过程逻辑
- teradata - Teradata 快速将文件(csv、excel)加载到带有系统日期加载日期列的表中
- r - as.Date 产生带有字符向量的 Nan
- python - 字符重复功能
- r - 如何对从字符串中提取的数字进行数学操作