自動遞增的數據我目前正在對火力地堡創造這樣的事情:上火力
"Assets": {
"asset001" : {
"name": "DESK001",
"owner: "owner's name",
"brand: "HP",
},
"asset002" : {
"name": "NOTE001",
"owner: "owner's name",
"brand: "Dell",
},
...
}
但是,我不知道如何爲自動遞增的「asset001」的價值......我已經看到了推()方法,但後來我不知道如何檢索數據。這是我到目前爲止有:
的JavaScript
//Get the inputs ID from HTML
var inputName = document.getElementById("inputName");
var inputOwner = document.getElementById("inputOwner");
var inputBrand = document.getElementById("inputBrand");
var inputAsset = document.getElementById("inputAsset");
//Set values on FireBase
btnAsset.addEventListener('click', e => {
//Get inputs data
const asset = inputAsset.value;
const owner = inputOwner.value;
const brand = inputBrand.value;
const name = inputName.value;
//database reference
var rootRef = firebase.database().ref().child("Assets");
//setar os valores
rootRef.child(asset).child("owner").set(owner);
rootRef.child(asset).child("brand").set(brand);
rootRef.child(asset).child("name").set(name);
Firebase文檔明確建議對有序集合使用'push()':https://firebase.google.com/docs/database/web/lists-of-data。還有豐富的經驗反對使用連續的,連續的數字索引,比如你在這裏嘗試。請參閱https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html –