【问题标题】:Saving and Getting Data / Rows to and from PouchDB在 PouchDB 中保存和获取数据/行
【发布时间】:2016-01-06 13:12:23
【问题描述】:

我对 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 在追加时如何识别哪些记录是新的,哪些记录是旧的。

【问题讨论】:

  • 把vm.getInvoicesLocal()的代码放上去..?

标签: angularjs ionic-framework couchdb pouchdb


【解决方案1】:

好吧,我正在研究同一种类型..!这就是我让它工作的方式..!

    $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();..! 希望这对你有帮助..!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多