【问题标题】:reactjs/react-native wait for promise to resolve before proceedingreactjs/react-native 等待promise解决后再继续
【发布时间】:2016-12-01 00:09:24
【问题描述】:
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() 方法中设置响应。任何其他建议将不胜感激。

提前致谢。

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 2013-04-25
      • 2019-11-01
      相关资源
      最近更新 更多