【问题标题】:Error: Reference.update failed: First argument contains an invalid key错误:Reference.update 失败:第一个参数包含无效键
【发布时间】:2018-08-18 08:34:11
【问题描述】:

我在 firebase 上遇到此错误(使用 vue.js):

第一次一切顺利,我可以根据需要多次运行以下功能。

addSpace: function (newSpace) { 
  let userId = firebaseApp.auth().currentUser.uid;  
  const key = spacesRef.push().key;  // creating the key once
  console.log(key); 
  spacesRef.child(key).update(this.newSpace); }

但是,如果当我运行另一个函数(参见下面的函数 AddDept)时,addSpace 函数会抛出错误:

addDept: function(space, dept, newDept, event) {
  this.newSpace = space;//get current space
  const deptKey = deptsRef.push().key; // create Dept Key
  let spaceKey = space['.key']; 
  console.log(spaceKey)
  var deptNode = spacesRef.child(spaceKey).child("hasDepts"); 
  deptNode.child(deptKey).set(true);
  deptsRef.child(deptKey).set(this.newDept);
  deptsRef.child(deptKey).child("spaceName").set(space.name);
  deptsRef.child(deptKey).child("spaceKey").set(spaceKey);
  this.newDept.name = '';
  this.newDept.comments = '';
  this.newSpaceKey= '';
  },

这里到底发生了什么?

Error: Reference.update failed: First argument contains an invalid key 
 (.key) in path /.key. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

我已经控制台记录了所有参数,它们看起来很正常。我也尝试过对参数进行字符串化,但没有成功。 感谢所有帮助。

【问题讨论】:

标签: javascript firebase vue.js


【解决方案1】:

我只需要 删除空格['.key'];到addDept函数

谢谢@skribe

【讨论】:

    猜你喜欢
    • 2021-03-03
    • 1970-01-01
    • 2021-02-12
    • 2020-04-07
    • 1970-01-01
    • 2013-07-14
    • 2017-09-12
    • 1970-01-01
    • 2015-01-31
    相关资源
    最近更新 更多