问题描述
我正在推送Firebase中的数据,但是我想在我的数据库中存储唯一的ID。
可以有人告诉我,如何推送与唯一的id数据。
我想这样
write()$ {
var key = ref.push()。key();
var newData = {
id:key,
Website_Name:this.web_name.value,
用户名:this.username.value,
密码:this.password。值,
website_link:this.web_link.value
}
firebase.database()。ref()。push(newData);
$ b
错误是ReferenceError:ref is not定义
您可以使用函数 key任何ref对象的c>
$ / $> $ / $> $ / $> b I am pushing data in firebase, but i want to store unique id in my database also .can somebody tell me,how to push the data with unique id. i am trying like this error is "ReferenceError: ref is not defined" You can get the key by using the function https://stackoverflow.com/a/36774761/2305342 https://stackoverflow.com/a/34437786/2305342 in your case : 这篇关于在Firebase中使用push()时如何获取唯一的ID并存储在我的数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
writeUserData(){
var myRef = firebase.database()。ref()。push();
var key = myRef.key();
var newData = {
id:key,
Website_Name:this.web_name.value,
用户名:this.username.value,
密码: this.password.value,
website_link:this.web_link.value
}
myRef.push(newData);
}
writeUserData() {
var key= ref.push().key();
var newData={
id: key,
Website_Name: this.web_name.value,
Username: this.username.value,
Password : this.password.value,
website_link : this.web_link.value
}
firebase.database().ref().push(newData);
}
key()
of any ref objectwriteUserData() {
var myRef = firebase.database().ref().push();
var key = myRef.key();
var newData={
id: key,
Website_Name: this.web_name.value,
Username: this.username.value,
Password : this.password.value,
website_link : this.web_link.value
}
myRef.push(newData);
}