我有一个名为Favorite tags的表。它有字段 - 标签,用户(指针分配用户objectid).where用户可以存储标签,并将用户对象作为指针存储在用户字段中,用户从收藏夹中删除标签
存储/更新:工作正常。
ParseObject favtagobject = new ParseObject("Favourite");
favtagobject.put("Tag", "#" + keyword);
favtagobject.put("User", ParseUser.getCurrentUser());
favtagobject.saveInBackground();
从表中删除/删除标记:以下代码无效
ParseObject favtagobject = new ParseObject("Favourite");
favtagobject.put("Tag", "#" + keyword);
favtagobject.put("User", ParseUser.getCurrentUser());
favtagobject.deleteInBackground(new DeleteCallback() {
@Override
public void done(com.parse.ParseException arg0) {
// TODO Auto-generated method stub
System.out.println("deleted the tag succesfully");
}
});
我想从表中删除一行,我知道要删除哪一行。请帮帮我。
答案 0 :(得分:6)
基本上,当您使用新的ParseObject("收藏")时,'它将构造一个新的ParseObject。在您调用任何.save()变体之前,数据库中不存在此parseObject。因此当你这样做时
ParseObject favtagobject = new ParseObject("Favourite");
favtagobject.put("Tag", "#" + keyword);
favtagobject.put("User", ParseUser.getCurrentUser());
favtagobject.deleteInBackground(new DeleteCallback() {
@Override
public void done(com.parse.ParseException arg0) {
// TODO Auto-generated method stub
System.out.println("deleted the tag succesfully");
}
});
您所做的只是创建一个新对象,该对象在您的数据库中不存在然后尝试删除它?您正在寻找的是
ParseQuery<ParseObject> query = ParseQuery.getQuery("Favourite");
query.whereEqualTo("Tag", "#" + keyword);
query.whereEqualTo("User", ParseUser.getCurrentUser());
query.getFirstInBackground(new FindCallBack() {
@Override
public void done(ParseObject object, com.parse.ParseException arg0) {
// TODO Auto-generated method stub
object.delete();
object.saveInBackground();
}
}););
这将首先从您的数据库中获取对象,然后从表中删除该行并保存对该对象所做的更改!
答案 1 :(得分:0)
感谢Bart de Ruijter。这对我也有用。
ParseQuery<ParseObject> query = ParseQuery.getQuery("Objects");
query.getInBackground(objectID, new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
try {
object.delete();
object.saveInBackground();
Intent dashboard = new Intent(getApplicationContext(),DashboardActivity.class);
Toast.makeText(getApplicationContext(), "Deleted Successuly.", Toast.LENGTH_SHORT).show();
startActivity(dashboard);
} catch (ParseException e1) {
e1.printStackTrace();
}
}
});