在我的云代码中,我想检索“消息”类中的第一个对象。然后我想从该对象中获取一些信息,将其发送到另一个类,最后从我最初从中提取的“消息”类中删除该对象。下面是我的代码,但它不起作用。我应该如何返工?
我应该使用与“销毁”方法(例如 collection.remove)不同的方法吗?
Parse.Cloud.afterSave("sendMessage", function(Parse.Message, response) {
var body = null;
var senderName = null;
var senderId = null;
var randUsers = [];
var query = new.Parse.Query(Parse.Message);
query.find({
success: function(results){
body.push(results[1].get("messageBody"));
senderName.push(results[1].get("senderName"));
senderId.push(results[1].get("senderId"));
results[1].destroy({
success: function(results[1]){
//the first object in the class "Messages" was deleted
}, error: function(results[1], error){
//the first object was not deleted
}
});
response.success(getUsers);
}, error: funtion(error){
response.error("Error");
}
});
});
为避免混淆:“getUsers”是一个任意函数调用。
最佳答案
与条目重复的问题;
Query entire class vs first object in the class
然而,如果你想删除一个特定的对象,你需要一些唯一标识该对象的东西
目的。然后,一种方法是使用 Parse 对象 id 从类中删除对象。
通过云删除对象,需要使用ParseObject的destroy方法。但是如果你有多个对象,那么你可以使用 destroyAll 方法。下面是 JavaScript API 上 ParseObject 删除方法的一个示例;
var yourClass = Parse.Object.extend("YourClass");
var query = new Parse.Query(yourClass);
query.get("yourObjectId", {
success: function(yourObj) {
// The object was retrieved successfully.
yourObj.destroy({});
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
}
});
希望这可以帮助,
问候。
关于javascript - 从 Parse.com 删除特定对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26208937/