【发布时间】:2018-12-07 04:56:14
【问题描述】:
我定义了一个获取查询的承诺。我有一个 json 数组:
fetch('query')
.then(response =>response.json())
.then(json => { blabla})
我想在promise之外重用json作为函数参数:
render(){
return(
<View onLayout={this.myFonction(json)>
</View>)}
myFunction =(json)=>{
var array = json.names
array.maps(value => {
return (
<Icon
name='heart'
type='emo'
color='red'
onPress={this.onPressIcon(value)} />);
});
}
我得到的只是它是未定义的。 甚至可以重用一个promise参数吗?
【问题讨论】:
-
用产生问题的实际代码更新您的问题。
-
.then(myFunction)? -
我更新了我的问题
-
你的
onLayout表达式中的json来自哪里?不,不等待就无法从承诺中获得价值。 -
因为我没有找到在我看来调用我的函数的方法。我知道这很糟糕
标签: react-native promise