更新中單場我創建「_id」,「名稱」和「狀態」字段pouchDB文件。然而,我發現,如果我想更新文件的「狀態」字段,然後我還需要指定所有其他領域我不是改變以及否則他們將被刪除。也就是說,如果我沒有在更新時指定「名稱」字段,則文檔中不再有「名稱」字段。如何將pouchDB文件
function createFriendSchedule(friend){
pouchDB.put({
_id : friend['id'],
name : friend['name'],
status: "new"
}, function(err, response){
createAndDispatchEvent("friend Schedule created");
});
}
這是更新文檔
function changeFriendStatus(friend){
pouchDB.get(friend['id'], function(err, retrieved){
pouchDB.put({
_id : friend['id'],
_rev : retrieved._rev, //need to specify _rev otherwise conflict will occur
name : retrieved.name, //if you don't specify name should remain the samme as before, then it will be left off the record!
status : friend['status']
}, function(err, response){
if(err){
console.log("COULDN'T CHANGE FRIEND STATUS");
} else { createAndDispatchEvent("friend status changed") }
});
});
}
這裏的代碼是用來拉出來的記錄
window.pouchDB.query(
{map : map},
{reduce : false},
function(err, response){
var responseRows = response['rows'];
var cleanedList = [];
_.each(responseRows, function(friend){
cleanedList.push({'_id' : friend['key'][0], 'name' : friend['key'][1], 'status' : friend['key'][2] });
});
window.reminderList = cleanedList;
console.log(window.reminderList);
createAndDispatchEvent("Returned reminder list");
});
如果我不指定「名稱」的代碼在更新域,在pouchDB.query信號發送的()調用返回的數組包含在那裏我想到了「名」的值是一個空值。
感謝您創建這樣一個真棒圖書館:)我真的認爲所有的事情可以在瀏覽器中完成!對於任何希望能夠更新單個(或多個)字段而不必顯式更新所有其他字段的人,我已經發布了一個可能的解決方法。 – JoeyC