Update line at Parse.com

What I have when the edit button is pressed, the values ​​in the two input fields create a new line, and the old line is discarded. Below is the code I used, but I want the original line to be updated and not deleted., Live example , how the code below works.

editBtn.onclick = function () { alert("Edit Btn"); alert(name.value + " " + Lname.value); contact.save(null, { success: function (contact) { contact.set("FirstName", name.value); contact.set("LastName", Lname.value); contact.save(); object.destroy({ success: function (myObject) { alert("destroy"); location.reload(); }, error: function (myObject, error) { alert("Error: " + error.code + " " + error.message); } }); } }); } 

just to clarify. I want to update the rows without creating a new one while deleting the old one.

EDIT: Link to the above question asked on the parsing forums.

EDIT: Additional information added to the link as a response to the comment.

EDIT: I added this code that actually edits the first name ("NewFname") but will not update the last name ("NewLame").

 editBtn.onclick = function () { var query = new Parse.Query(Contact); query.equalTo("LastName", NewLname.value); query.first({ success: function (Contact) { Contact.save(null, { success: function (contact) { contact.set('FirstName', NewFname.value); contact.set('LastName', NewLname.value); contact.save(); location.reload(); } }); } }); } 

Where I have query.equalTo ("LastName", NewLname.value), I tried to include objectId ie (query.equalTo ("objectId"), but this did not work for me.

any ideas?

Thomas

+6
source share
1 answer

I was able to update this code.

 editBtn.onclick = function () { var query = new Parse.Query(Contact); query.equalTo("objectId", object.id); query.first({ success: function (Contact) { Contact.save(null, { success: function (contact) { contact.set("FirstName", NewFname.value); contact.set("LastName", NewLname.value); contact.save(); location.reload(); } }); } }); } 
+8
source

Source: https://habr.com/ru/post/944539/


All Articles