【问题标题】:How to add new entry in firebase in webAPP如何在 webAPP 中的 firebase 中添加新条目
【发布时间】:2016-08-27 11:16:18
【问题描述】:

这是路径https://code.firebaseio.com/products2上的数据结构

现在我想在 products/2586/Variants 添加新条目。说条目是 112:真

这个函数我已经写好了。

$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);
};

但它正在删除所有旧条目。

如何在不触及旧条目的情况下添加新条目?

【问题讨论】:

    标签: javascript firebase firebase-realtime-database angularfire2


    【解决方案1】:

    使用.update 代替.set。 Set 删除所有以前的条目。

    ref.update(object) 也是如此,其中 object 是您尝试插入的 javscript 对象。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-28
      • 2011-09-01
      • 2013-12-07
      • 2019-08-27
      • 2012-03-31
      • 1970-01-01
      • 1970-01-01
      • 2018-12-25
      相关资源
      最近更新 更多