couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Gabriel <a...@barbalex.ch>
Subject updating document with $db.saveDoc: How come not anymore saved fields stay in the document?
Date Sun, 15 May 2011 19:34:33 GMT
Hi
I'm a new to java script and not a very experienced programmer so please
excuse stupid mistakes...

I am updating a document using this code:

$("#submitButton").live("click", function(event) {
var docId = "{{id}}";
$db.openDoc(docId, {
success: function(doc) {
doc.Modus = "einfach";
doc.Typ = "Beobachtung";
doc.User = User;
doc.bArtGruppe = $("select#bArtGruppe").val();
doc.bArtName = $("select#bArtName").val();
if ($("input#bArtId").val() != null){
doc.bArtId = $("input#bArtId").val();
}
if ($("input#bAutor").val()!=null){
doc.bAutor = $("input#bAutor").val();
}
if ($("input#oXKoord").val()!=null){
doc.oXKoord = $("input#oXKoord").val();
}
... and e few more ...
saveDocument(doc);
},
error: function() {
alert("Diese Beobachtung kann nicht geƶffnet werden: " + docId);
}
});
});

function saveDocument(document)
{
$db.saveDoc(document, {
success: function() {
window.open("../../index.html", target="_self");
},
error: function() {
alert("Beobachtung kann nicht gespeichert werden: " + document._id + ", " +
document.bArtName);
}
});
}

I know for sure that doc.oXKoord (for example) is not set when the input has
no value (I placed an alert inside the if. It only alerts, wehn the input
has a value).

What I dont understand is why doc.oXKoord stays in the document and keeps
the previous value. All the set values are updated and also the rev.

Unfortunately allmost all the documentation I could find so far is on put
and post, not on $db.saveDoc. With put and post, I read in the documentation
that if you update a document and you want do keep a field-value, you have
to save it again. And I could not find any way to remove a single
field-value without saving a new document.

Am I doing something wrong?
Is there a good documentation for the $db methods? (I know
http://arandomurl.com/random/jquery.couch.js-docs/symbols/$.couch.db.html for
instance. But real examples would be very helfpul).

Thanks for any help!

Alexander Gabriel

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message