【问题标题】:PouchDB not working in Chrome (kind of)PouchDB 在 Chrome 中不起作用(有点)
【发布时间】:2014-04-04 12:59:31
【问题描述】:

我现在正在尝试让 PouchDB 工作两天 - 一些简单的东西可以工作,有些则不行。

很难找出原因,但我终于设法找出了一个问题 - 是不是问题 随着 IndexDB 破坏数据库并再次创建 OR 承诺在 PouchDB 中实现,我不知道。

无论如何 - 下面的代码在 Firefox 中工作到最后,但在 Chorme 中只到达“正在创建数据库...”并且没有任何警告就停止(在调试器下永远不会到达“发布记录”)

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
</head>

<body>

<script src="lib/pouchdb/dist/pouchdb-nightly.js"></script>

<script>
    new PouchDB('test')
        .then(function (db) {
            console.log("Destroying database.. ");
            return db.destroy()
        })
        .then(function () {
            console.log("Creating database.. ");
            return new PouchDB('test');
        })
        .then(function (db) {
            console.log("Posting record.. ");
            return db.post({name: 'name'});
        })
        .then(function(info){
            console.log("Checking id of inserted record: " + info.id);
        })
        .catch(function (error) {
            console.log(error.message);
        });

</script>

</body>
</html>

任何解决方法?

我需要“销毁数据库->然后创建新的->然后做一些事情”的操作流程,每次都可以在每个浏览器中工作-我尝试使用承诺和回调-得到代码示例或 IndxedDB 错误 11 中的结果...

【问题讨论】:

  • 这里没问题,在 Chrome 中创建和删除数据库。

标签: pouchdb


【解决方案1】:

您的承诺链中发生了一些奇怪的事情,但这里有一个解决方法,效果很好:

new PouchDB('test')
        .then(function (db) {
            console.log("Destroying database.. ");
            return db.destroy();
        })
        .then(function () {
            console.log("Creating database.. ");
            return new PouchDB('test').then(function (db) {
                console.log("Posting record.. ");
                return db.post({name: 'name'});
            })
            .then(function(info){
                console.log("Checking id of inserted record: " + info.id);
            });
        })
        .catch(function (error) {
            console.log(error.message);
        });

输出:

Destroying database.. Creating database.. Posting record.. Checking id of inserted record: 0613FFBA-518F-4F20-A1DD-D18E59A4340B

不过,为了安全起见,我已在 PouchDB 上提交了 an issue

【讨论】:

    猜你喜欢
    • 2015-06-07
    • 2013-06-27
    • 1970-01-01
    • 2019-10-24
    • 2016-08-29
    • 1970-01-01
    • 1970-01-01
    • 2018-07-25
    • 1970-01-01
    相关资源
    最近更新 更多