Tau*_*san 1 reactjs react-native react-native-ios
我想得到一个 json 文件作为回报。
这是我正在使用的提取函数
handleApi(){
return
fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.movies;
})
}
Run Code Online (Sandbox Code Playgroud)
正在按钮单击事件上调用此函数。
handleSubmit() {
console.log(
this.handleApi();
)
Run Code Online (Sandbox Code Playgroud)
但我得到这个 Promise对象作为回报不是预期的数据
Promise {_40: 0, _65: 0, _55: null, _72: null}_40: 0_55: null_65: 0_72: null__proto__: Object
更简化的
handleApi(){
return
fetch('https://facebook.github.io/react-native/movies.json')
.then(response =>
response.json().then(jsonObj => return jsonObj.movies)
)
}
Run Code Online (Sandbox Code Playgroud)
然后在 handleSubmit
handleSubmit() {
this.handleApi().then(movies => {
console.log('Print list of movies:', movies);
});
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6049 次 |
| 最近记录: |