2017-05-31 57 views
0
var updates = {}; 
updates['article/' + keyval] = new_sub_tag1; 
updates['sub_tags/' + tagname] = new_sub_tag2; 
ref.update(updates); 

上述代码完全用新的代码替换所有的元素。firebase数据库特定字段更新多个位置

现在,我使用下面的代码来更新特定的字段而不是覆盖。

ref.child('article/' + keyval).update ({ 
    sub_tag: sub_tag_name 
}); 

相反,我正在寻找在事务中多个位置的一个特定字段更新。

回答

0

当更新多个下级位置,一定要要要在更新地图的左侧,以更新位置整个路径

var updates = {}; 
updates['article/' + keyval + '/property'] = new_sub_tag1_value; 
updates['sub_tags/' + tagname + '/property'] = new_sub_tag2_value; 
ref.update(updates); 
+0

真棒...谢谢你坦率:) – user1322692