【发布时间】:2015-11-18 09:25:26
【问题描述】:
使用 Parse 时,如果我有一个名为 people 的对象和两列,一列称为 name,另一列称为 age。用户可以输入一个名称以匹配已存储在 Parse 中的名称,还可以输入要添加到该特定名称的年龄。如何让它搜索用户输入的名称,如果名称与用户输入的匹配,则将年龄添加到该特定名称?
【问题讨论】:
标签: javascript parse-platform updating
使用 Parse 时,如果我有一个名为 people 的对象和两列,一列称为 name,另一列称为 age。用户可以输入一个名称以匹配已存储在 Parse 中的名称,还可以输入要添加到该特定名称的年龄。如何让它搜索用户输入的名称,如果名称与用户输入的匹配,则将年龄添加到该特定名称?
【问题讨论】:
标签: javascript parse-platform updating
您无法在对象中保存任何内容,除非您有权访问其 objectId,因此您需要执行搜索以及保存。您需要找到与用户输入的姓名关联的对象,然后添加年龄值并保存。代码变成这样:
var query = new Parse.Query("people");
query.equalTo("name", inputName);
query.find().then( function(objects) { // query and search for object(s)
var person = objects[0]; // get the first object, there can be more than one obviously
person.set("age", inputAge); // set the age
return person.save(); // save the age value in object
}).then(function() {
// success
}, function(error) {
// error
});
【讨论】: