Api 如何在react native中呈现JSON对象
在本页中: 我无法在文本组件中呈现速率, 如何在react native中显示速率Api 如何在react native中呈现JSON对象,api,react-native,Api,React Native,在本页中: 我无法在文本组件中呈现速率, 如何在react native中显示速率 async componentDidMount(){ const coin = await Fetch.fetchCoins(); this.setState({coin}); } {this.props.shop.map((item)=>{ return( <View key={item.base}> <Text>{item.date}<
async componentDidMount(){
const coin = await Fetch.fetchCoins();
this.setState({coin});
}
{this.props.shop.map((item)=>{
return(
<View key={item.base}>
<Text>{item.date}</Text>
<Text>{item.rates}</Text>
</View>
)
})
}
鉴于费率是一个对象,我建议添加一个函数,大致如下所示:
renderRates = (rates) => {
let rows = [];
Object.keys(rates).forEach(key => {
rows.push(<Text>{key + ' ' + rates[key]}</Text>)
});
return rows;
}
然后将{item.rates}替换为{this.renderRatesthis.coin.rates}什么类型的组件?你想干什么?请添加相关代码。我将使用文本组件显示费率,但无法获取元素ex:NZD值。请将代码添加到postasync组件didmount{const coin=wait Fetch.fetchCoins;this.setState{coin};}{this.props.shop.mapitem=>{return{item.date}{item.rates}}看起来这是一个不完整的示例,但有两个潜在问题:1假设第二位代码实际上是render的一部分,您是否真的在迭代这个.state.coin?2 rates是一个对象,您也需要迭代它