【问题标题】:Not able to update firebase realtime database in angularjs (web)无法在 angularjs(网络)中更新 firebase 实时数据库
【发布时间】:2016-08-14 07:36:24
【问题描述】:

这是我在 firebase 中更新记录的代码。

$scope.EditBrand = function(brand)  {
    var key = brand.id;
    var fredNameRef = firebase.database().ref('all-brands/' + key);

    fredNameRef.set(brand, function(error) {
      if (error) {
        alert ('some error')
      } else {
        alert ('updated')
      }
    });
}

我检查了密钥,它是正确的。

但是当调用这个函数时,这是错误的。

angular.js:12477Error: Firebase.update failed: 第一个参数在路径 /$$hashKey 中包含无效的键 ($$hashKey)。键必须是非空字符串,并且不能包含“.”、“#”、“$”、“/”、“[”或“]” 在错误(本机)

我的代码或逻辑有什么问题??

【问题讨论】:

  • 我认为您的密钥/ID 无效。 $$hashKey 是您的品牌 ID 吗?如果是,FIrebase 不接受键中的“$”。
  • @Odonno,我的品牌 ID 字符串,如 23、34、45 等
  • 根据groups.google.com/forum/#!topic/angular/pI0IgNHKjxw,您应该创建一个临时对象以避免角度生成的字段。所以,在你的方法中添加这一行:var brandObject = angular.fromJson(angular.toJson(brand)); 并在方法的其余部分使用brandObject
  • 谢谢。它现在工作。请发表你的答案,所以我会接受。

标签: javascript angularjs


【解决方案1】:

根据https://groups.google.com/forum/#!topic/angular/pI0IgNHKjxw,你应该创建一个临时对象来避免angular生成的字段。因此,在您的方法中添加这一行:var brandObject = angular.fromJson(angular.toJson(brand)); 并在方法的其余部分中使用 brandObject

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 2022-12-01
    • 1970-01-01
    相关资源
    最近更新 更多