This is the data that i want to retrieve
How can I retrieve the data without knowing the unique ID?
var query = firebase.database().ref("/Venue").orderByKey();
query.on("value", function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var key = childSnapshot.key;
var childData = childSnapshot.val();
console.log(childData);
});
});
答案 0 :(得分:2)
使用<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
<div class="wrapperleft">
<div class="bio">
<ul>
<div id="generationbutton" class="opacity">
<li>01 Generation Anxiety</li>
</div>
<div id="lekhenabutton" class="opacity">
<li>02 Lekhenaporter.com</li>
</div>
<div id="bodysbutton" class="opacity">
<li>03 Body(s) Under Negotiation</li>
</div>
<div id="glitterbutton" class="opacity">
<li>04 Glitter Boy Cosmetics</li>
</div>
<div id="juicebutton" class="opacity">
<li>05 Juice WRLD Cover Art</li>
</div>
</ul>
</div>
<div class="back">
<h1>← Back</h1>
</div>
</div>
<div class="wrapperright">
<div class="display">
<img src="http://media-s3-us-east-1.ceros.com/vevo/images/2017/11/07/8d018e81643b41c3561b5ab4f5bf504b/iamddb-contact-sheet1.jpg" />
</div>
<div id="generationanxiety">
<img src="https://dazedimg-dazedgroup.netdna-ssl.com/786/azure/dazed-prod/1180/0/1180791.jpg" />
</div>
<div id="lekhenaporter">
<img src="http://kendrickbrinson.com/wp-content/uploads/2014/03/YoungThug_Portraits-029.jpg" />
</div>
<div id="bodys">
<img src="https://www.thunderstudios.com/wp-content/uploads/2016/03/Calvin-15.jpg" />
</div>
<div id="glitter">
<img src="https://4c79id2ej5i11apui01ll2wc-wpengine.netdna-ssl.com/wp-content/uploads/2018/01/IAMDDB-Gallery-3.jpg" />
</div>
<div id="juice">
<img src="https://www.thunderstudios.com/wp-content/uploads/2016/03/Calvin-15.jpg" />
</div>
</div>
</div>
来提供帮助。它返回对象属性值的数组
由于Object.values
仅具有一个属性,因此您可以轻松获取其值,它将位于索引0处
.Data
答案 1 :(得分:0)
您可以获得对象javascript的第一键
Object.keys(childData.Data)[0];
获取对象javascript的第一键值
Object.values(childData.Data)[0];
var obj = {
Venue: {
Block_A: {
Data: {
lpanss :{
Date: "19/03/2019",
Humi: 30,
Temp: 50,
Time: "12:56"
}
}
}
}
};
//key
console.log(Object.keys(obj.Venue.Block_A.Data)[0]);
//values
console.log(Object.values(obj.Venue.Block_A.Data)[0]);
答案 2 :(得分:0)
使用Object.values
:
var obj = {
Venue: {
Block_A: {
Data: {
Date: "19/03/2019",
Humi: 30,
Temp: 50,
Time: "12:56"
}
}
}
};
console.log(Object.values(obj.Venue.Block_A.Data));