以下代码按预期工作。但我有两个问题:
// Save default Account Types
var refTypes = this.housesRef.child(key + "/memberaccounttypes/");
refTypes.push({ name: 'Checking', icon: '0' });
refTypes.push({ name: 'Savings', icon: '0' });
refTypes.push({ name: 'Credit Card', icon: '0' });
refTypes.push({ name: 'Debit Card', icon: '0' });
refTypes.push({ name: 'Investment', icon: '0' });
refTypes.push({ name: 'Brokerage', icon: '0' });
我正在使用Firebase SDK 3
答案 0 :(得分:1)
每次通过这种方式进行推送都会导致往返Firebase。您可以通过检查" Web Sockets"来轻松验证这一点。浏览器调试工具的网络选项卡上的窗格。
如果您希望将其作为单个更新运行,则可以将它们合并到多位置更新中:
var refTypes = this.housesRef.child(key + "/memberaccounttypes/");
var updates = {};
updates[refTypes.push().key] = { name: 'Checking', icon: '0' };
updates[refTypes.push().key] = { name: 'Savings', icon: '0' };
updates[refTypes.push().key] = { name: 'Credit Card', icon: '0' };
updates[refTypes.push().key] = { name: 'Debit Card', icon: '0' };
updates[refTypes.push().key] = { name: 'Investment', icon: '0' };
updates[refTypes.push().key] = { name: 'Brokerage', icon: '0' };
refTypes.update(updates);
,这几乎不会节省任何时间/带宽