我在 firebase 中推送数据,但我也想在我的数据库中存储唯一 ID。有人可以告诉我,如何推送具有唯一 ID 的数据。
我正在尝试这样
writeUserData() {
var key= ref.push().key();
var newData={
id: key,
websiteName: this.webname.value,
username: this.username.value,
password : this.password.value,
websiteLink : this.weblink.value
}
firebase.database().ref().push(newData);
}
错误是“ReferenceError:ref 未定义”
原文由 komal deep singh chahal 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用任何 ref 对象的函数
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);
}
”`