Firebase警告:用户回调引发了异常。 TypeError:无法将undefined或null转换为object

时间:2017-09-19 20:43:52

标签: javascript firebase-realtime-database

我一直在使用Firebase Web应用程序,并且在访问数据库的某些元素时突然间,在尝试使用Object.keys以创建一系列键时,它一直抛出一系列异常。迭代每个对象。

这个确切的功能到目前为止工作得很好,数据库的某些子元素仍然没有任何错误。

以下是我遇到问题的代码以及Chrome中引发的错误。任何建议将不胜感激

//reference to firebase database at Flags/Employee t
    var ref = database.ref('Flags/Employee');
    //Take a snapshot of all Green Flags stored and use as training data for knn
    ref.on('value', function(snapshot){
        //Array of flag objects
        var storedFlags = snapshot.val();

        //Array of hashcodes used to access flags
        var keys = Object.keys(storedFlags);

        //Loop through each flag stored in the database at Flags/Employee
        //Find the flags with the smallest distance to the current flag
        //Store in a heap for later access
        for(var i = 0; i < keys.length; i++){
            var currentLookup = storedFlags[keys[i]];

以下是调用Object.keys函数时发生的错误:

firebase-storage.js:3476 Uncaught TypeError: Cannot use 'in' operator to search for 't' in 2
at M (firebase-storage.js:3476)
at t.cr (firebase-storage.js:3476)
at e.onMessage (firebase-storage.js:3476)
at e.nt (firebase-storage.js:3476)
at e.handleIncomingFrame (firebase-storage.js:3476)
at WebSocket.mySock.onmessage (firebase-storage.js:3476)
M @ firebase-storage.js:3476
t.cr @ firebase-storage.js:3476
(anonymous) @ firebase-storage.js:3476
e.nt @ firebase-storage.js:3476
e.handleIncomingFrame @ firebase-storage.js:3476
mySock.onmessage @ firebase-storage.js:3476




VM2298:1 Uncaught SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at r (firebase-storage.js:3476)
    at e.nt (firebase-storage.js:3476)
    at e.handleIncomingFrame (firebase-storage.js:3476)
    at WebSocket.mySock.onmessage (firebase-storage.js:3476)
r @ firebase-storage.js:3476
e.nt @ firebase-storage.js:3476
e.handleIncomingFrame @ firebase-storage.js:3476
mySock.onmessage @ firebase-storage.js:3476
VM2299:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at r (firebase-storage.js:3476)
    at e.nt (firebase-storage.js:3476)
    at e.handleIncomingFrame (firebase-storage.js:3476)
    at WebSocket.mySock.onmessage (firebase-storage.js:3476)
r @ firebase-storage.js:3476
e.nt @ firebase-storage.js:3476
e.handleIncomingFrame @ firebase-storage.js:3476
mySock.onmessage @ firebase-storage.js:3476
recommendations.js:635 null



firebase-storage.js:3476 FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at file:///home/tyler/Desktop/My%20Websites/DistroRecommendations/recommendations.js:638:24
    at t (https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:64323)
    at https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:59730
    at z (https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:10438)
    at t.raise (https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:110130)
    at t.In (https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:109788)
    at t.raiseEventsForChangedPath (https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:109610)
    at Object.onComplete (https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:140458)
    at https://www.gstatic.com/firebasejs/4.3.0/firebase.js:324:129429 
R @ firebase-storage.js:3476
(anonymous) @ firebase-storage.js:3476
setTimeout (async)
z @ firebase-storage.js:3476
t.raise @ firebase-storage.js:3476
t.In @ firebase-storage.js:3476
t.raiseEventsForChangedPath @ firebase-storage.js:3476
(anonymous) @ firebase-storage.js:3476
(anonymous) @ firebase-storage.js:3476
e.vr @ firebase-storage.js:3476
t.vr @ firebase-storage.js:3476
t.cr @ firebase-storage.js:3476
(anonymous) @ firebase-storage.js:3476
e.nt @ firebase-storage.js:3476
e.handleIncomingFrame @ firebase-storage.js:3476
mySock.onmessage @ firebase-storage.js:3476




firebase-storage.js:3476 Uncaught TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at recommendations.js:638
    at t (firebase-storage.js:3476)
    at firebase-storage.js:3476
    at z (firebase-storage.js:3476)
    at t.raise (firebase-storage.js:3476)
    at t.In (firebase-storage.js:3476)
    at t.raiseEventsForChangedPath (firebase-storage.js:3476)
    at Object.onComplete (firebase-storage.js:3476)
    at firebase-storage.js:3476

0 个答案:

没有答案