I'm grabbing a URL and parsing it to create a variable called list. I have this variable printing in the console inside and outside of the function. I also have tried grabbing the URL again inside of the function. Firing this function gives me an error of:
Reference.update failed: First argument must be an object containing the children to replace.
How can I pass the correct variables to the function so that I can write to Firebase?
The JS is:
var getQueryString = function ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
var list = getQueryString('list', window.location.href);
console.log(list);
document.getElementById('list').innerText = list;
function accept(){
var list = getQueryString('list', window.location.href);
console.log("accept", "list", list);
var user = firebase.auth().currentUser;
var uid = user.uid;
console.log("accept", "uid", uid);
firebase.database().ref('userprofile/' + uid + '/list').update(list);
return firebase.database().ref('userlists/' + list + '/members/' + uid).update('true');
}
What you're doing now is equivalent to a set()
operation:
return firebase.database().ref('userlists/' + list + '/members/' + uid).set('true');
Alternatively you can perform the update one level higher:
var updates = {};
updates[uid] = 'true';
return firebase.database().ref('userlists/' + list + '/members/' + ).update(updates);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.