我正在创建一个应用程序,其中使用frontend中的reactjs和firebase作为后端注册用户数据。我可以将数据保存到firebase。我可以编辑和删除数据,但无法将编辑后的数据保存到firebase。我该怎么做才能编辑数据?我使用了Dim emptyRow As Long, addr as string
emptyRow = Range("Z100000").End(xlUp).Offset(1, 0).Row
addr = Cells(emptyRow,40).Address()
Cells(emptyRow, 43).Formula = "=IF(" & addr & "=0, """", VLOOKUP(" & _
addr & ",'Job Category'!$G$10:$I$12, 3, TRUE))"
但仍然没有用。
child_changed
答案 0 :(得分:3)
根据文件:https://www.firebase.com/docs/web/guide/
var ref = new Firebase(" https://docs-examples.firebaseio.com/web/saving-data/fireblog");
//suppose you have similar kind of data in your data base which was created like this
var usersRef = ref.child("users");
usersRef.set({
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
},
gracehop: {
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"
}
});
//then to change data
usersRef.child("alanisawesome").set({
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
});
usersRef.child("gracehop").set({
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"
});
//remember that using 'set' causes overwrite data at that localtion to avoid this you can also use 'update' . like if your db looks like this
{
"users": {
"alanisawesome": {
"date_of_birth": "June 23, 1912",
"full_name": "Alan Turing",
"nickname": "A Machine"
},
"gracehop": {
"date_of_birth": "December 9, 1906",
"full_name": "Grace Hopper",
"nickname": "A Grace"
}
}
}
//then you can do this
usersRef.update({
"alanisawesome/nickname": "Alan The Machine"
"gracehop/nickname": "Amazing Grace"
});
答案 1 :(得分:1)
您可以在loadData函数中保存id来获取id。所以你可以这样做
saveUser(oldUser, newUser){
console.log('olduser',oldUser);
console.log('newuser', newUser);
// TODO - optimize this code
const foundUser = _.find( this.state.userInfo, user =>
user.name === oldUser.name
);
const foundContact = _.find( this.state.userInfo, user =>
user.contact === oldUser.contact
);
const foundAddress = _.find( this.state.userInfo, user =>
user.address === oldUser.address
);
const foundEmail = _.find( this.state.userInfo, user =>
user.email === oldUser.email
);
const foundUsername = _.find( this.state.userInfo, user =>
user.username === oldUser.username
);
const foundPassword = _.find( this.state.userInfo, user =>
user.password === oldUser.password
);
console.log('foundUser', foundUser);
console.log('foundUser.name',foundUser.name);
foundUser.name = newUser.name;
foundContact.contact = newUser.contact;
foundAddress.address = newUser.address;
foundEmail.email = newUser.email;
foundUsername.username = newUser.username;
foundPassword.password = newUser.password;
}
const editUserRef = new Firebase('https://***.firebaseio.com/users').child(oldUser.id);
console.log('edit',editUserRef);
editUserRef.update(foundUser);