简体   繁体   English

打字机错误:无法读取未定义的属性“长度”

[英]Typer Error: Cannot read property 'length' of undefined

I'm creating a node.js app and implementing the scheduler app. 我正在创建一个node.js应用程序并实现调度程序应用程序。 I'm following this walkthrough: https://dhtmlx.com/blog/using-dhtmlxscheduler-with-node-js/ 我正在按照以下演练进行操作: https : //dhtmlx.com/blog/using-dhtmlxscheduler-with-node-js/

When I navigate to the /data page, it says cannot read property 'length' of undefined. 当我导航到/ data页面时,它说无法读取未定义的属性“ length”。 I went to the github page and downloaded app.js word for word. 我去了github页面并逐字下载了app.js。

Here is app.js portion throwing error: 这是app.js部分抛出错误:

app.get('/data', function(req, res){
db.event.find().toArray(function(err, data){
    //set id property for all records
    for (var i = 0; i < data.length; i++)
        data[i].id = data[i]._id;

    //output response
    res.send(data);
});
});

This example works fine. 这个例子很好用。 I guess, in your case, mongoskin fails to connect to mongodb for some reasons. 我猜,就您而言,由于某些原因, mongoskin无法连接到mongodb。 If I change some parts in this path mongodb://localhost/testdb (for testing purpose, put some random string) , mongodb will complain about problem with url , and I'll get an error TypeError: Cannot read property 'length' of undefined from node js, because there will be no data fetched from database. 如果我在此路径中更改了某些部分mongodb://localhost/testdb (出于测试目的,请放置一些随机字符串),则mongodb将抱怨url问题,并且我将收到错误TypeError: Cannot read property 'length' of undefined从节点js中TypeError: Cannot read property 'length' of undefined ,因为将不会从数据库中获取任何数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM