Firebase POST自定义ID [英] Firebase POST custom ID
本文介绍了Firebase POST自定义ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用POST方法时,是否可以在Firebase中设置自定义ID?像这样:
is there a way to set a custom ID in Firebase when using the POST method? something like:
{
"users": {
"user_one": {
"username": "jdoe",
"password": "123"
}
}
}
我正在研究Vue.js项目,并试图像这样挽救一些学生及其父母:
I'm working on a Vue.js project and trying to save some students and their parents like:
let padre = {
nombre: this.padre.nombre,
apellido: this.padre.apellido,
cedula: this.padre.cedula,
nacionalidad: this.padre.nacionalidad,
estado_civil: this.padre.estado_civil,
instruccion: this.padre.instruccion,
profesion: this.padre.profesion,
trabaja: this.padre.trabaja,
l_trabajo: this.padre.l_trabajo,
d_trabajo: this.padre.d_trabajo,
tlf_trabajo: this.padre.tlf_trabajo,
tlf_habitacion: this.padre.tlf_habitacion,
tlf_movil: this.padre.tlf_movil
}
axios.post('https://projectname.firebaseio.com/padres.json', padre)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
推荐答案
请确保使用put而不是post请求,否则您将在"user_one"内部使用自动生成的ID结束
Make sure to use the put instead of the post request else you'll end up with the auto generated id inside of your "user_one"
POST将给您:
{
"users": {
"user_one": {
"134134hnj34nuj134bn": {
"username": "jdoe",
"password": "123"
}
}
}
}
axios.put('https://projectname.firebaseio.com/padres/user_one.json',padre)
PUT将为您提供所需的内容.
{
"users": {
"user_one": {
"username": "jdoe",
"password": "123"
}
}
}
这篇关于Firebase POST自定义ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文