使用检索到的值更新firebase会显示错误Reference.child失败错误

时间:2017-09-20 09:48:30

标签: javascript firebase firebase-realtime-database reference

我试图更新检索到的firebase值,但收到错误:错误:Reference.child失败:第一个参数是无效路径=“”。路径必须是非空字符串,并且不能包含“。”,“#”,“$”,“[”或“]”firebase.js:324:31719,不确定是什么导致此问题。

以下是代码:

var ref=firebase.database().ref("REGISTRATION");
var key;

function callUpdateFunction(){
var email,name, gender, birthdate, phone, state, school, clas, classname;
    name = document.getElementById("name").value;
    email = document.getElementById("email").value;
    gender = document.getElementById("gender").value;
    birthdate = document.getElementById("birthdate").value;
    phone = document.getElementById("phone").value;
    state = document.getElementById("state").value;
    school = document.getElementById("school").value;
    clas = document.getElementById("clas").value;
    classname = document.getElementById("classname").value;

    var dataUpdate={};

    dataUpdate.name = name;
    dataUpdate.email = email;
    dataUpdate.gender = gender;
    dataUpdate.birthdate = birthdate;
    dataUpdate.phone = phone;
    dataUpdate.state = state;
    dataUpdate.school = school;
    dataUpdate.class = clas;
    dataUpdate.classname = classname;

在浏览器控制台窗口中,我此时收到错误

ref.child(key).set(dataUpdate).then(function()
{

    init();

    document.getElementById("EditContent").style.display="none";
})
}

1 个答案:

答案 0 :(得分:0)

在你的jsfiddle键行中实际上是10,但是你给了9,所以键值是空字符串,你的代码是

$('#append tr').find('td:eq(10)').hide(); //your hiding your key as td:eq(10) but in your get value you took 9's value.

 key = $(this).find('td:eq(9)').map(function () {return $(this).text();}).get().join(" "); 

因此将其更改为10并尝试更新您的数据。

See the updated js fiddle version