PouchDB 加载产生错误

PouchDB Load producing error

我正在尝试使用 PouchDB 使用以下代码片段将初始内容加载到我的数据库中:

db2.load('bloggr.txt').then(function() {
    // done loading!
}).catch(function(err) {
    // HTTP error or something like that
    console.log(err);
});

我正在使用 PouchDB Load 提供的一些示例内容。数据库已创建,记录已创建,但我在控制台中收到 Javascript 错误。

TypeError: Cannot read property 'db_name' of undefined
at pouchdb.load.js:56

查看第 56 行,我看到以下内容

var target = new db.constructor(info.db_name,

有人知道是什么原因造成的吗?

这对我来说很完美:

<!DOCTYPE html>
<html>
<head>
  <title>PouchDB-Load Test</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pouchdb/4.0.3/pouchdb.js"></script>
  <script src="https://rawgit.com/nolanlawson/pouchdb-load/master/dist/pouchdb.load.js"></script>
</head>
<body>
  <script type="text/javascript">
    var db2 = new PouchDB('http://localhost:5984/pouchdb-load-test/');
    console.log('Starting load');
    db2.load('bloggr.txt')
    .then(function() {
      console.log('Success!');
    })
    .catch(function(err) {
      // HTTP error or something like that
      console.log(err);
    });
  </script>
</body>
</html>

确保您的 CouchDB 配置中有 CORS enabled。它会因 file:// 而失败,因此需要来自 Web 服务器的 运行。