gpt4 book ai didi

node.js - 错误无法读取未定义的属性 '0'

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:50 24 4
gpt4 key购买 nike

我正在为我的移动应用程序构建一个nodejs服务器,当我保存数据时遇到问题,我可以在我的data.jade中显示它

这是我的错误消息:

Cannot read property '0' of undefined
at jade_debug.unshift.lineno (eval at <anonymous> (/Users/****/Documents/Node- server/node_modules/jade/lib/jade.js:160:8), <anonymous>:33:21)
at eval (eval at <anonymous> (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:160:8), <anonymous>:65:4)
at res (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:161:38)
at Object.exports.render (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:257:10)
at Object.exports.renderFile (/Users/****/Documents/Node-server/node_modules/jade/lib/jade.js:293:18)
at View.exports.renderFile [as engine] (/Users/Yanis/Documents/Node-server/node_modules/jade/lib/jade.js:278:21)
at View.render (/Users/****/Documents/Node-server/node_modules/express/lib/view.js:76:8)
at Function.app.render (/Users/****/Documents/Node-server/node_modules/express/lib/application.js:505:10)
at ServerResponse.res.render (/Users/****/Documents/Node-server/node_modules/express/lib/response.js:756:7)
at /Users/****/Documents/Node-server/index.js:44:9

index.js:

app.get('/:collection', function(req, res) {
var params = req.params;
collectionDriver.findAll(req.params.collection, function (error, objs) {
if (error) {
console.log("mongo db error"+error);
objs = [];
}
else {
if (req.accepts('html')) {
res.render('data', {objects: objs, collection: req.params.collection});
}
else {
res.set('Content-Type', 'application/json');
res.send(200, objs);
}
}
});
});

最后是我的 data.jade :

#objects
table(border=1)
if objects.length > 0
- each val, key in object[0]
th= key
- each obj in objects
tr.obj
- each val, key in obj
td.key= val

正如你所看到的,我的对象没有在 data.jade 中“定义”,我不知道为什么。我不知道问题是来自jade文件还是de.js。你们谁有解决办法吗?

最佳答案

object[0] 可能应该是 data.jade 中的 objects[0]

关于node.js - 错误无法读取未定义的属性 '0',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25934190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com