示例代码是:
$db.saveDoc(doc, {
success: function () {
// Do something with the ID.
},
error: function () {
alert("Cannot save the thread.");
}
});
在成功回调函数中,如何获取刚刚保存的文档的ID?
当您发送 POST /db/doc 请求时,几乎所有 jquery.couch 函数都会使用从 http 请求返回的数据调用成功回调,
{"ok":true,"id":"ad5c9fc93ae3b6f5f9809357a30003fe","rev":"1-2a91bdd9ee1e3e5e6302741132d7c415"}
被返回,所以
$db.saveDoc(doc, {
success: function (data) {
var id = data.id;
},
error: function () {
alert("Cannot save the thread.");
}
});