如何updateChildValue
多个child
?如下例所示,但具有单个事务。保持key3
完整
/*
user = {
user1 : {
key1 : -1,
key2 : -1,
key3 : 111,
},
user2 : {
key1 : -1,
key2 : -1,
key3 : 111,
},
}
*/
NSDictionary <NSString *, NSNumber *> *dictionary = @{
@"key1" : @111,
@"key2" : @111,
};
FIRDatabaseReference *ref = [[FIRDatabase database] reference];
[[ref
child:@"user1"]
updateChildValues:dictionary];
[[ref
child:@"user2"]
updateChildValues:dictionary];
答案 0 :(得分:1)
要通过对updateChildValues
的一次调用获得相同的结果,请展开字典以包含所有更新及其完整路径:
NSDictionary <NSString *, NSNumber *> *dictionary = @{
@"user1/key1" : @111,
@"user1/key2" : @111,
@"user2/key1" : @111,
@"user2/key2" : @111,
};
FIRDatabaseReference *ref = [[FIRDatabase database] reference];
[ref
updateChildValues:dictionary];