【问题标题】:delete and update using pouchdb使用 pouchdb 删除和更新
【发布时间】:2015-12-13 01:39:07
【问题描述】:

hye huys,我需要帮助才能使用 pouchdb 进行删除和更新。现在创建和读取数据可以工作。只是删除和更新还不行。 这是我的数据库

application.service('Database', ['$q', '$window',
function($q, $window)
{
    var db = new $window.PouchDB('web-sample');

    this.delete = function(documentId, documentRev, options)
    {
        return $q.when(db.delete(documentId, documentRev, options));
    };

    this.get = function(documentId)
    {
        return $q.when(db.get(documentId));
    };
}

]);

这是我的服务

application.service('Arrears', ['$q', 'Database',
function($q, Database)
{
    this.remove = function(documentId, documentRev, options)
        {
          return Database.delete(documentId, documentRev, options);
        };


    this.update = function()
    {
        return Database.update()
    };
}

]);

这是我的控制器。

application.controller('ArrearsManagementReadAllController', ['$location', '$mdSidenav', '$routeParams', '$scope', 'arrears',
function($location, $mdSidenav, $routeParams, $scope, arrears)
{
    $scope.arrears = arrears;
    $scope.remove = function(id)
    {
        $location.path('/arrears_management/all');
    };

    var arrears = {
        owner_name: '',
        owner_id: '',
        account_no: '',
        title_no: '',
        address: '',
        house_no: '',
        floor: '',
        lot: '',
        block: '',
        locality: '',
        total_outstanding: '',
        last_receipt_no: '',
        last_pay_date: '',
        last_paid_amount: '',
    };

    var actions = {};

    actions.submit = function(arrears)
    {
        Arrears.update(arrears).
            then(function(response)
            {
                $location.path('/arrears_management/all');
            });
    };
}]);

如果你们都知道如何解决我的问题,请发表评论。谢谢

【问题讨论】:

    标签: angularjs crud pouchdb


    【解决方案1】:

    尝试删除时,您可能会遇到冲突,因此可能需要重试删除,但在使用递归调用时,使用计数器设置重试次数,然后抛出错误,如果无法删除,则捕获结果出于冲突以外的某种原因。

    同样,在尝试更新时,您需要先获取最新的文档修订,然后再尝试放置。同样,您需要处理诸如 404 和 409 错误之类的冲突。如果您收到 404,请在重试之前尝试删除修订。使用 409 重试即可。同样,如果使用递归调用可能最好进行一定次数的重试,然后针对其他条件抛出错误并捕获结果。

    【讨论】:

      猜你喜欢
      • 2015-07-04
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多