跟踪器重新计算功能的例外:无法读取属性' 0'未定义的

时间:2015-03-19 02:16:07

标签: javascript meteor

我在控制台日志中收到此错误

Exception from Tracker recompute function: Cannot read property '0' of undefined
TypeError: Cannot read property '0' of undefined
at null.<anonymous> (http://104.236.39.101:3000/client/templates/Professor/professorLectureView.js?026ec69298583f9fdeecadcdf9f2899a402df744:48:41)
at http://104.236.39.101:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1821:18
at Function.Template._withTemplateInstanceFunc (http://104.236.39.101:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:3382:12)
at http://104.236.39.101:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1820:29
at Object.Blaze._withCurrentView (http://104.236.39.101:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2105:12)
at viewAutorun (http://104.236.39.101:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1819:18)
at Tracker.Computation._compute (http://104.236.39.101:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:308:36)
at Tracker.Computation._recompute (http://104.236.39.101:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:322:14)
at Tracker.flush (http://104.236.39.101:3000/packages/tracker.js?21f0f4306879f57e10ad3a97efe9ea521c5b5775:452:14) 

我相信这是因为我在this.autorun函数中调用了数组seriesData

this.autorun(function(){

    feedbacks = Router.current().data();
    feedbacks = feedbacks.sort(function(a,b){return a.postedDate.getTime() - b.postedDate.getTime()});


    if(Session.get('timeBarChart')){
        *irrelavent code*
    }     
        seriesData = [[],[],[],[],[]];
        categoryData = [];
        var topicName = "";
        for(var i = 0, len = feedbacks.length; i < len; i++) {
            comVal = feedbacks[i].commentType;
            if(comVal == 0) {
                *irrelavent code*
            }
            else{
                seriesData[comVal-2][seriesData[0].length - 1]++;   <--------------this line
            }
    }
}

但是我不明白为什么这会导致问题,特别是因为seriesData被初始化了几行。我认为它可能是由流星更新到1.0引起的,因为它在0.9时仍然有效。

1 个答案:

答案 0 :(得分:0)

不要因为数组上的索引超出范围而导致属性为null。它与自动运行没有任何关系。