我正在使用parse.com并更新当前用户数据。我只想更新其他数据中的当前用户信息,例如" UserInfo"表,我想在其中放入一些更新的值。
当前用户的代码段如下:
ParseUser user = ParseUser.getCurrentUser();
user.put("firstName", fName.getText().toString());
user.put("lastName", lName.getText().toString());
user.put("email", mailText.getText().toString());
user.put("contactNumber", mobileText.getText().toString());
/*user.put("dob", medCond.getText().toString());
user.put("lastName", medication.getText().toString());
user.put("lastName", docInfo.getText().toString());*/
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
// dismissLoadingDialog();
if (e == null) {
Toast.makeText(getApplicationContext(), "User Profile Has Been Updated!",
Toast.LENGTH_SHORT).show();
} else {
Logs.e(getClass().getName(), e.toString());
Toast.makeText(getApplicationContext(), "Exception/n"+e,
Toast.LENGTH_SHORT).show();
// howMessage(e.getMessage());
}
}
});
但是我想在我的另一个表中更新几个值。以下代码在数据库中创建每个新条目。我想只进行更新而不是创建新行。
final ParseObject update = new ParseObject("UserInfo");
update.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException arg0) {
// TODO Auto-generated method stub
update.put("blood", spinnerOsversions.getSelectedItem().toString());
update.put("doc", "");
update.put("medicate", "ldldm");
update.put("medical", "cdlmldm");
update.put("medicalCond", "lalalla");
update.put("allergy", "Twice A Day");
update.saveInBackground();
}
});
答案 0 :(得分:2)
我对Parse不太熟悉,但我想如果你将userId作为主键添加到UserInfo表中,在尝试保存时,它应该更新该元组而不是由于主键约束而创建新元组。
答案 1 :(得分:1)
在更新之前,您需要先检索对象。通过objectId或其他查询:
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
// Retrieve the object by id
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
public void done(ParseObject gameScore, ParseException e) {
if (e == null) {
// Now let's update it with some new data. In this case, only cheatMode and score
// will get sent to the Parse Cloud. playerName hasn't changed.
gameScore.put("score", 1338);
gameScore.put("cheatMode", true);
gameScore.saveInBackground();
}
}
});