Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
152
rated 0 times [  154] [ 2]  / answers: 1 / hits: 67003  / 9 Years ago, sun, january 10, 2016, 12:00:00

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 somebody help me please?



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

addUser(tester1, []);

var addUser = function(name, edges){
if(!checkIfUsernameExists(name) && !checkIfNodeNameExists(name) && !checkIfEdgeNameExists(name)){
var time = Firebase.ServerValue.TIMESTAMP;

//HERE: I think the error is on this line
refs.users.update(objify(name, filler));

refs.users.child(name).set({
id : time,
edges : filler
});
refs.users.child(name).child(edges).update({
to : filler,
from : filler
});

addNode(new Node(name, time, name));

for(var e in edges){
refs.users.child(name).child(edges/to).update(objify(edges[e].name, true));
addEdge(new Edge(edges[e].name, time, edges[e].to, edges[e].arrows));
//TODO add a from edge so that you know who wants to eat you
}
refs.users.child(name).child(edges/to).set({filler : null});
} else {
alert(user/node/edge name taken.);
}
};

More From » firebase

 Answers
8

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}



[#63779] Thursday, January 7, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryanulyssesb

Total Points: 91
Total Questions: 105
Total Answers: 102

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
ryanulyssesb questions
Sat, Mar 20, 21, 00:00, 3 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
Mon, Mar 9, 20, 00:00, 4 Years ago
Sun, Jul 7, 19, 00:00, 5 Years ago
;