Firebase多位置更新覆盖而不是更新值 [英] Firebase multi-location update overwriting instead of updating value
问题描述
我目前遇到与本文所述完全相同的问题:
当前,Firebase单节点 .update()
函数不会覆盖其他相同级别的子节点.
但是,当使用多位置 ref.update()
时,同一级别的所有其他子节点都将被覆盖,本质上起 .set()
函数的作用./p>
有没有办法我实际上可以在不覆盖所有相同级别的子节点的情况下运行多位置 .update()
?
基于此github问题: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/313
一种可能的解决方法是将要更新的每个字段定义为单独的更新,并将其作为原子更新的一部分进行更新,这样,您实际上将更新需要更新的每个单个字段吗?
var companiesPath ='companies/company_name';var usersPath ='users/user_nickname';var data = {};data [companiesPath] =最佳公司名称";data [usersPath] ='John';firebase.update(data);
因此,您无法更新完整的对象,您需要定位该对象的各个字段.我刚刚对其进行了测试,并且可以正常工作...
I'm currently have the exact same issue as outlined in this article:
Currently the Firebase single node .update()
function will not overwrite other same level child nodes.
However when using multi-location ref.update()
all other child nodes in the same level are overwriten, essentially acting as a .set()
function.
Is there someway I can actually run multi-location .update()
without overwriting all same level child nodes?
Based on this github issue: https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/313
One possible workaround would be defining each field you want to update as separate update, and update it as a part of atomic update, that way you would actually update each individual field needed to be updated?
var companiesPath = 'companies/company_name';
var usersPath = 'users/user_nickname';
var data = {};
data[companiesPath] = 'Best Company Name';
data[usersPath] = 'John';
firebase.update(data);
So you can't update the complete object, you need to target the individual fields of that object. I just tested it and this works...
这篇关于Firebase多位置更新覆盖而不是更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!