我是pouchdb的新手,这意味着我还没有成功实现使用它的应用程序。
现在这是我的问题,在我的控制器中我有两个功能:
var init = function() {
vm.getInvoicesRemote(); // Get Data from server and update pouchDB
vm.getInvoicesLocal(); // Get Data from pouchDB and load in view
}
init();
基本上在我的应用程序中,我有一个显示客户发票的视图,现在我希望客户能够在他们离线时仍能看到这些发票。我看过几个pouchdb和couchdb的例子,但都使用了" todo"这个例子并没有真正提供太多信息。
现在我很困惑我在花费数小时理解couchdb并安装它的重点是什么,如果最终我将使用我的API从我的服务器检索数据。
同样,当返回数据时,pouchdb如何识别哪些记录是新的以及哪些记录在追加时是旧的。
答案 0 :(得分:0)
$scope.Lists = function () {
if(!$rootScope.connectionFlag){
OfflineService.getLocalOrdersList(function (localList) {
if(localList.length > 0) {
$scope.List = localList;
}
});
}else{
if(!$scope.user){
}else {
Common.callAPI("post", '***/*************', $scope.listParams, function (data) {
if (data !== null) {
$scope.List = data.result;
OfflineService.bulkOrdersAdd_updateLocalDB($scope.List);
}
});
}
}
};
因此,如果在线以及基于connectionFlag离线
,$scope.List
将被填充
注意:OfflineService
和Common
是服务。
通话方法:
$ionicPlatform.ready(function () {
OfflineService.configDbsCallback(function(res) {
if(res) {
$scope.Lists();
}
});
});
你可以尝试直接调用$scope.Lists();
..!
希望这有助于你......!