【发布时间】:2014-12-31 07:09:16
【问题描述】:
我才刚刚开始学习 PouchDB。在对文档进行了几次审核并查看了许多示例之后,我根据自己的需要调整了 app.js,这只是为了预填充数据库并显示所有记录(是的,我知道这不是正确的 PouchDB 术语 - 抱歉)。此时,屏幕保持空白,Chrome 开发工具控制台中没有显示任何输出。
你能告诉我代码在什么时候失败了吗?
app.js:
(function() {
'use strict';
// Create new DB
var tl = document.getElementById('todo-list');
var db = new PouchDB('todos');
return console.log("Created DB");
// Insert data into DB (post docs with auto-IDs)
db.bulkDocs([
{
title: 'Dog',
name: 'German Shepherd'
},
{
title: 'Dog',
name: 'Don\'s Rotweiler'
},
{
title: 'Cat',
name: 'Carrie\'s Siamese'
},
{
title: 'Cat',
name: 'Persian'
}
], function(err, response) {
if (!err) {
return console.log('Rows: ' + response.total_rows);
}
if (err) {
return console.error(err);
}
});
// Redraw screen on change
db.changes({
since: 'now',
live: true
}).on('change', showTodos);
function showTodos(){
db.allDocs({include_docs: true}, function(err, response){
if(!err) {
tl.innerHTML = "";
todo.rows.forEach(function(todo){
tl.innerHTML += '<hr><p>' + todo.title + '<br>' + todo.name + '</p>';
return console.log(response);
});
} if(err) {
return console.error(err);
}
});
}
PouchDB.debug.enable('*');
});
【问题讨论】:
标签: pouchdb