我将HTML div保存到PouchDB" board"宾语。我有这个功能来获取所有已保存的div:
window.viewBoards = function() {
var results = db.allDocs({include_docs: true}, function(err, response) { });
}
结果将div埋在其中:
Promise {cancel: function, [[PromiseStatus]]: "resolved", [[PromiseValue]]: Object}cancel: function (){return this}__proto__: Promise[[PromiseStatus]]: "resolved"[[PromiseValue]]: Objectoffset: 0rows: Array[5]0: Object1: Object2: Object3: Object4: Objectdoc: Object_id: "2014-12-05T20:48:57.327Z"_rev: "1-68823c9c66374d831b482b9a67354301"board: "↵ <div class="square" style="background-color: rgb(162, 136, 99);"></div><div class="square" style="background-color: rgb(25, 108, 184);"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div><div class="square"></div>"__proto__: Objectid: "2014-12-05T20:48:57.327Z"key: "2014-12-05T20:48:57.327Z"value: Object__proto__: Objectlength: 5__proto__: Array[0]total_rows: 5__proto__: Object
如何保存&#34; board&#34;对象变量然后用jQuery放入页面?我尝试使用这样的点符号:
var board = results.[[PromiseStatus]]. ???
但是[[PromiseStatus]]的事情让它变得棘手,我不确定该怎么做。
答案 0 :(得分:2)
所以你看到的是Promise的回应。 PouchDB有两种使用其API的方式:回调(即function (err, response)
)和Promises(例如db.allDocs().then(function (){...}
)。
所以在你的情况下,最好的办法是:
db.allDocs({include_docs: true}).then(function (results) {
/* handle results */
}).catch(function (error) {
/* handle error */
})
我建议您查看the PouchDB guide to async code,如果您遇到问题,可以使用大量实时代码示例来帮助您! :)