简体   繁体   English

如何在webAPP中的Firebase中添加新条目

[英]How to add new entry in firebase in webAPP

This is data structure on path https://code.firebaseio.com/products2 这是路径https://code.firebaseio.com/products2上的数据结构

在此处输入图片说明

Now i want to add new entry on products/2586/Variants. 现在,我想在products / 2586 / Variants上添加新条目。 Say entry is 112: true 假设输入为112:是

I have written this function. 我已经写了这个功能。

$scope.AddProductVariant2 = function(Product, Variant)  {
  //ProductService.AddProductVariant (Product, Variant);

  var key = Product.ProductID;
  var productRef = firebase.database().ref();
  var updates = {};
  var variant = {};
  variant[Variant.VariantID] = true;
  updates['products2/' + key + '/' + 'Variants'] = variant;
  /*
  firebase.database().ref('products2/' + key + '/' + 'Variants').set({
    variant
  });
 */

 return productRef.update(updates);
};

But it is erasing all old entries. 但这会删除所有旧条目。

How to add new entry without touching old one here? 如何在不触摸旧条目的情况下添加新条目?

Use .update instead of .set . 使用.update而不是.set Set removes all previous entries. Set删除所有先前的条目。

So do ref.update(object) where object is your javscript object you're trying to insert. 所以ref.update(object) ,其中object是您要插入的javscript对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM