简体   繁体   English

从PouchDB回调函数获取数据?

[英]Get data from PouchDB callback function?

I need to get all the documents from PouchDB database and store them in $scope variable (AngularJS). 我需要从PouchDB数据库中获取所有文档,并将它们存储在$ scope变量(AngularJS)中。 Can anyone tell me how to get the 'doc' from the callback function? 谁能告诉我如何从回调函数中获取“ doc”?

db.allDocs({include_docs: true, descending: true}, function(err, doc) {
    $scope.info = doc;

});

Outside of this code, $scope.info is undefined, the doc object is not stored in this variable 在此代码之外,未定义$ scope.info,doc对象未存储在此变量中

I assume that the db is a 3rd party code not part of angularjs or a service, then you need to do it like 我假设db是第三方代码,而不是angularjs或服务的一部分,那么您需要这样做

db.allDocs({include_docs: true, descending: true}, function(err, doc) {
  $scope.$apply(function(){  
    $scope.info = doc;
  })
});

because angularjs is not aware of changes that happens somewhere else 因为angularjs不了解其他地方发生的变化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM