问题描述
我所拥有的是当单击一个编辑按钮时,两个输入字段中的值创建一个新行并删除旧行。下面是我使用的代码,但我想要的是原始行被更新而不是删除。 ,了解如何使用以下代码。
editBtn.onclick = function(){
alert(Edit Btn);
alert(name.value ++ Lname.value);
contact.save(null,{
成功:功能(联系){
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.code ++ error.message);
}
});
}
}) ;
}
只是为了澄清我想在删除时更新行而不是创建新行旧的。
编辑:在解析论坛中询问上述问题。
编辑:链接中添加了更多信息作为对评论的回复。
此代码实际编辑的第一个名称(NewFname)但它不会更新最后一个name(NewLname)。
editBtn.onclick = function(){
var query =新的Parse.Query(联系方式);
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();
}
});
}
});
}
我有query.equalTo(LastName,NewLname.value),我试图输入objectId ie(query.equalTo(objectId);但这对我不起作用。
任何想法?
Thomas
我设法用这段代码更新了它。
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();
}
});
}
});
}
What I have is when an edit button is clicked the values in two input fields create a new row and the old row is dropped.Below is the code i used but what i want is that the original row is updated and not deleted. Live Example of how using 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 not create a new one while deleting the old one.
EDIT: Link to above question asked in parse forums.
EDIT: more information added in link as a reply to a comment.
EDIT: I added this code which is actually editing the first name ("NewFname") but It wont update the last name ("NewLname").
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 put in objectId i.e. (query.equalTo("objectId"); but that didn't work for me.
any ideas?
Thomas
I managed to get it updating with 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();
}
});
}
});
}
这篇关于在Parse.com中更新一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!