2016-01-05 66 views
0

我对pouchdb很新,这意味着我还没有成功地实现一个使用它的应用程序。保存并从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

把代码vm.getInvoicesLocal()..? –

回答

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); 
        } 
       }); 
      } 
     } 
    }; 

所以,$scope.List会如果是网上和离线基于connectionFlag

注填:OfflineServiceCommon的服务。

调用方法:

$ionicPlatform.ready(function() { 
     OfflineService.configDbsCallback(function(res) { 
      if(res) { 
       $scope.Lists(); 
      } 
     }); 
    }); 

ü可以尝试直接调用$scope.Lists(); ..! 希望这可以帮助你..!