【发布时间】:2017-10-25 20:29:14
【问题描述】:
假设我在 firebase 数据库中有一些数据,比如 my database image
现在我想更新 trxId,其中 photoId 等于“B063527”。我无法解决这个问题,请有人帮助我。我该如何解决这个问题?提前谢谢。
【问题讨论】:
-
你有密码吗?
标签: android firebase firebase-realtime-database
假设我在 firebase 数据库中有一些数据,比如 my database image
现在我想更新 trxId,其中 photoId 等于“B063527”。我无法解决这个问题,请有人帮助我。我该如何解决这个问题?提前谢谢。
【问题讨论】:
标签: android firebase firebase-realtime-database
首先,获取特定记录,然后修改其模型对象中的属性,然后将其保存。再次针对相同的 id;
private void getValue(String key){
mdatabaseRef.child("user").orderBykey().equals(key).SingleValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child: dataSnapshot.getChildren()){
String key = child.getKey();
Object object = postsnapshot.getValue(Object.class);
updateData(object );
}
private updateData(Object object) {
object.setName("test123");
mDatabaseReference.child("user").child(object.getId()).setValue(object);
}
【讨论】:
private void writeNewData(String userId, String name, String email) {
User user = new User(name, email);
mDatabase.child("users").child(userId).setValue(user);
}
n your case you can do something like:
mDatabase.child("UID2").child("KEY2").setValue(yourNewValueOrObject);
If you want to update a specific value, you should be more concise:
mDatabase.child("UID2").child("KEY2").child("email").setValue(newEmail);
【讨论】: