【发布时间】:2018-02-07 05:47:04
【问题描述】:
我正在调用此代码:
Permissions.check('photo')
.then(response => {
...
});
这里我可以使用响应对象来检查值。
但我想用 await 来称呼它:
async function test() {
let test = await Permissions.check('photo');
return test;
}
...
let result = test();
但这会给我返回如下所示的 Promise 对象:
Promise {_40: 0, _65: 0, _55: null, _72: null}
我通常在response 中获得的价值在这里我获得result._55。
我该怎么做才能得到合适的对象?
【问题讨论】:
-
如果您将
await和then结合使用,它将起作用。我认为这是一个不好的做法。试试let test; await Permissions.check('photo').then((response) => test=response); -
我之前问过一个类似的问题,这是接受的答案中非常有用的信息:stackoverflow.com/questions/45765114/…
标签: javascript react-native es6-promise