在 PouchDB 中创建数据库
Creating database in PouchDB
我目前正在使用 Microsoft Visual Studio 2015 和 Cordova 进行移动开发。
我尝试浏览 PouchDB 文档并使用他们提供的任何内容
function insertDB() {
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://localhost:5984/todos");
db.put({
_id: 'mydoc',
title: 'Heroes'
}).then(function (response) {
// handle response
}).catch(function (err) {
console.log(err);
});
PouchDB.sync('remoteDB', 'http://localhost:5984/todos');
}
我使用按钮调用 insertDB() 函数,但出现错误。
<button onclick="insertDB()">Click Me!</button>
我一直收到错误消息说 localDB 未定义,PouchDB 未定义。我知道我做错了,因为我对 PouchDB 很陌生,以前从未使用过它。
请问我哪里做错了?
解决方案:
我发现我链接了pouchdb的min.js但是找不到文件,所以报undefined的错误。然后我使用 <script src="//cdn.jsdelivr.net/pouchdb/5.4.5/pouchdb.min.js"></script>
问题就解决了。
未定义表示您的 pouchdb 包未正确初始化
使用 npm 或 cdn
const PouchDB = require('pouchdb').default;
除下一行外一切正确(您的语法错误)
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://localhost:5984/todos");
PouchDB.sync('remoteDB', 'http://localhost:5984/todos');
更正
var db = new PouchDB("todos");//localdb
var remoteDB = new PouchDB("http://localhost:5984/todos");
PouchDB.sync('db', 'http://localhost:5984/todos');
在 pouchdb 中,当您调用下面的行时,db 将 create.if db 不存在
它更新数据库,如果已经存在
var db = new PouchDB("todos");
所以上面单行是通过put函数创建或者更新数据的
(如果你传递 _id 和 _rev)它会更新你的数据库
如果不传递 _id 和 _rev 则插入新行
导入你的 pouchdb
const PouchDB = require('pouchdb').default;
然后
function insertDB() {
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://localhost:5984/todos");
db.put({
_id: 'mydoc',
title: 'Heroes'
}).then(function (response) {
// handle response
}).catch(function (err) {
console.log(err);
});
PouchDB.sync('db', 'http://localhost:5984/todos');
}
我目前正在使用 Microsoft Visual Studio 2015 和 Cordova 进行移动开发。
我尝试浏览 PouchDB 文档并使用他们提供的任何内容
function insertDB() {
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://localhost:5984/todos");
db.put({
_id: 'mydoc',
title: 'Heroes'
}).then(function (response) {
// handle response
}).catch(function (err) {
console.log(err);
});
PouchDB.sync('remoteDB', 'http://localhost:5984/todos');
}
我使用按钮调用 insertDB() 函数,但出现错误。
<button onclick="insertDB()">Click Me!</button>
我一直收到错误消息说 localDB 未定义,PouchDB 未定义。我知道我做错了,因为我对 PouchDB 很陌生,以前从未使用过它。
请问我哪里做错了?
解决方案:
我发现我链接了pouchdb的min.js但是找不到文件,所以报undefined的错误。然后我使用 <script src="//cdn.jsdelivr.net/pouchdb/5.4.5/pouchdb.min.js"></script>
问题就解决了。
未定义表示您的 pouchdb 包未正确初始化 使用 npm 或 cdn
const PouchDB = require('pouchdb').default;
除下一行外一切正确(您的语法错误)
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://localhost:5984/todos");
PouchDB.sync('remoteDB', 'http://localhost:5984/todos');
更正
var db = new PouchDB("todos");//localdb
var remoteDB = new PouchDB("http://localhost:5984/todos");
PouchDB.sync('db', 'http://localhost:5984/todos');
在 pouchdb 中,当您调用下面的行时,db 将 create.if db 不存在
它更新数据库,如果已经存在
var db = new PouchDB("todos");
所以上面单行是通过put函数创建或者更新数据的 (如果你传递 _id 和 _rev)它会更新你的数据库
如果不传递 _id 和 _rev 则插入新行
导入你的 pouchdb
const PouchDB = require('pouchdb').default;
然后
function insertDB() {
var db = new PouchDB("todos");
var remoteDB = new PouchDB("http://localhost:5984/todos");
db.put({
_id: 'mydoc',
title: 'Heroes'
}).then(function (response) {
// handle response
}).catch(function (err) {
console.log(err);
});
PouchDB.sync('db', 'http://localhost:5984/todos');
}