Firebase.update failed : first argument contains undefined in property

前端 未结 4 1589
无人及你
无人及你 2021-02-04 23:47

I have a simple Firebase function that updates some data. However, the interpreter says that the first argument contains \"undefined\" in property \'users.tester1\'. Can somebod

4条回答
  •  萌比男神i
    2021-02-05 00:25

    When you pass an object to Firebase, the values of the properties can be a value or null (in which case the property will be removed). They can not be undefined, which is what you're passing in according to the error.

    Simply running this snippet in isolation shows the problem:

    var objify = function() {
      var rv = {};
        for (var i = 0; i < arguments.length; ++i)
          rv[arguments[i]] = rv[arguments[i+1]];
        return rv;
    }
    objify("name", "filler")
    

    Results in:

    {name: undefined, filler: undefined}

    My best bet is that you want to pass key/value pairs into objify as even/odd parameters. In that case you want to change the function to:

    var objify = function() {
      var rv = {};
        for (var i = 0; i < arguments.length; i+=2)
          rv[arguments[i]] = arguments[i+1];
        return rv;
    }
    objify("name", "filler")
    

    Results in:

    {name: "filler"}

提交回复
热议问题