reactjs / react-native在继续之前等待承诺解决

时间:2016-07-27 06:23:51

标签: reactjs react-native reactjs-flux react-native-android

DB.users.get_all(function(response){
  this.setState(result: response); // not required
  return response // required but not working for react-native-db-model
});

我可以从此方法返回响应吗?我正在使用react-native-db-model而不是在setState()方法中设置响应。任何其他建议将不胜感激。

先谢谢。

1 个答案:

答案 0 :(得分:1)

至于我阅读react-native-db-models的源代码,函数 get_all 没有返回任何内容,只是执行回调(https://github.com/darkrishabh/react-native-db-models/blob/master/index.js#L44

因此,您无法返回对变量的响应。因此,使用setState()将是IMO的最佳选择。