0

私は今、PouchDB を 2 日間動作させようとしています。

原因を特定するのは困難でしたが、最終的に 1 つの問題を特定することができました。それは、IndexDB がデータベースを破壊して再作成する問題か、または PouchDB での実装を約束するか、手がかりがありません。

とにかく、以下のコードは Firefox で最後まで機能しますが、Chorme では「データベースの作成中...」にしか到達せず、警告なしで停止します (デバッガーの下では「Posting record」に到達しません)。

<!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...

4

1 に答える 1

0

Promise チェーンで何かおかしなことが起こっていますが、問題なく動作する回避策を次に示します。

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に問題を報告しました。

于 2014-04-17T22:17:47.810 に答える