2017-01-13 74 views
0

火力地堡與返回null陣列和在Javascript

// Initialize Firebase 
 
var config = { 
 
    apiKey: "AIzaSyAGHEgm48s7_QkBwLw0UX-yCBLQg06zvdA", 
 
    authDomain: "fir-bef76.firebaseapp.com", 
 
    databaseURL: "https://fir-bef76.firebaseio.com", 
 
    storageBucket: "fir-bef76.appspot.com", 
 
    messagingSenderId: "207871344593" 
 
}; 
 
firebase.initializeApp(config); 
 
var ref = firebase.database().ref("employeeAttendace") 
 
    .child("427188EI/2017/1"); 
 

 
ref.once("value").then(function(data) { 
 
    console.log(data.val()); 
 
});
<script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script> 
 

 
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 

 
</head> 
 

 
<body> 
 

 
</body> 
 

 
</html>

我存儲火力點我的一些數據對象。但是在獲取數據的時候,我得到的是數組填充null和對象而不是JSON對象。


JSON Structure: 
    employeeAttendance 
     -4114EI 
     -2017 
      -1 
      -1:{Key:value} 
      -2:{Key:Value} 
      -3:{Key:Value} 
      -4:{Key:Value} 
      -5:{Key:Value} 

火力點取代碼:

var ref=firebase.database().ref("employeeAttendance/4114EI/2017/1"); 
ref.once("value",function(data){ 


    //Here i am getting 
[null,null,{key,value},{key,value},{key,value}] 
     }); 

請幫助我如何解決空值問題

Expected Output

Output Getting

回答

0

我得到了解決方案。實際上JSON結構不符合firebase規則的格式。