[英]How can I use fetch api in react native that have 2 parameter?
我有这个API
http://myIP/api/soffices/{service_id}/{governorate_id}
我想从中获取数据,但是我不能在这里输入我的代码
componentDidMount(){
let service_id = this.props.navigation.getParam('service_id');
let governorate_id = this.props.navigation.getParam('governorate_id');
return fetch('http://myIP/api/soffices/' + service_id + / governorate_id)
.then((response) => response.json())
.then((responseJson) => {
this.setState({
dataSource: responseJson.data,
}, function(){
});
})
}
返回时:
<FlatList
data={this.state.dataSource}
renderItem={({item}) =>
<CardSection>
<Text>{item.office_name}</Text>
</CardSection>
}
/>
它给我这个错误:JSON解析错误:无法识别的令牌“ <”
这似乎是语法错误。 用这个:
return fetch('http://myIP/api/soffices/' + service_id + '/' + governorate_id)
要么
return fetch(`http://myIP/api/soffices/${service_id}/${governorate_id}`)
请注意,在第二种形式中,我们使用`而不是'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.