【发布时间】:2016-05-07 15:21:56
【问题描述】:
在为我的 Ionic 项目测试 pouchDB 后,我尝试使用加密袋加密我的数据。但是我在使用设计文档时遇到了问题。我使用了以下代码:
-
我的一份设计文件:
var allTypeOne = { _id: '_design/all_TypeOne', views: { 'alle_TypeOne': { map: function (doc) { if (doc.type === 'type_one') { emit(doc._id); } }.toString() } } }; -
初始化我的数据库:
function initDB() { _db = new PouchDB('myDatabase', {adapter: 'websql'}); if (!_db.adapter) { _db = new PouchDB('myDatabase'); } return _db.crypto(password) .then(function(){ return _db; }); // add a design document _db.put(allTypeOne).then(function (info) { }).catch(function (err) { } } -
获取type_one的所有文档:
function getAllData { if (!_data) { return $q.when(_db.query('all_TypeOne', { include_docs: true})) .then(function(docs) { _data = docs.rows.map(function(row) { return row.doc; }); _db.changes({ live: true, since: 'now', include_docs: true}) .on('change', onDatabaseChange); return _data; }); } else { return $q.when(_data); } }
此代码在不使用加密袋的情况下也能正常工作,但如果我插入 _db.crypto(...) ,我的列表中不会显示任何数据。谁能帮我?提前致谢!
【问题讨论】:
标签: ionic-framework pouchdb documents