read only certain fields in firebase

前端 未结 2 1153
予麋鹿
予麋鹿 2020-12-11 10:00

If I have a database like

users: {
  user1: { 
    name:\'qwert\', 
    id: 123,
    num: 9999 
  },
  user2: { 
    name:\'zxcvb\', 
    id: 456,
    num:          


        
2条回答
  •  暖寄归人
    2020-12-11 10:53

    To retrieve only the names of the users, then try the following:

    firebase.database().ref().child("users").on("value", function (snapshot) {
      snapshot.forEach(function(childSnapshot) {
       var name=childSnapshot.val().name;
      });
    });
    

    Here the snapshot is users, then you iterate inside user1 and user2 to be able to access the names of these users and retrieve them.

提交回复
热议问题