Node.js 回调错误:TypeError:无法读取属性';行';未定义的
我正在产品列表中添加分页。但我一直有错误:Node.js 回调错误:TypeError:无法读取属性';行';未定义的,node.js,postgresql,express,handlebars.js,Node.js,Postgresql,Express,Handlebars.js,我正在产品列表中添加分页。但我一直有错误: console.log(data.rows); ^ 这是我数据库中正在查询的js文件: list: (client, filter, callback) => { const productListQuery = ` SELECT * FROM products ORDER BY id `; client.query(productListQuery, (req, result)=>{ con
console.log(data.rows);
^
这是我数据库中正在查询的js文件:
list: (client, filter, callback) => {
const productListQuery = `
SELECT *
FROM products
ORDER BY id
`;
client.query(productListQuery, (req, result)=>{
console.log(result.rows);
callback(result.rows);
});
这是我的路由器。进入我的服务器。js:
app.get('/products', function (req, res, next) {
Product.list(client, {limit: 8}, {offset: (req.query.p - 1) * 8}, {
}, function (products) {
res.render('/client/product-list', {
products: products,
title: 'Products',
pagination: {
page: req.query.p || 1,
limit: 8,
n: req.query.p || 1
}
});
});
});
这仅仅意味着您的
数据
是未定义的
,而在JavaScript未定义的
对象中没有任何属性或值
我建议您在使用前先试用一下
当您调用数据库时,响应中有一个错误,因为您没有正确处理响应,所以出现了这个错误
要了解未定义的与其他对象值之间的差异:
let a;
let b = 22;
let c = null;
let d = {
'a': 22,
'b': [4,5,6]
};
console.log(a); // undefined
console.log(a.b); // TypeError: Cannot read property 'b' of undefined
console.log(b); // 22
console.log(b.c); // undefined
console.log(c); // null
console.log(d.a); // 22
console.log(d.b); // [4,5,6]
console.log(e); // ReferenceError: e is not defined
这仅仅意味着您的数据
是未定义的
,而在JavaScript未定义的
对象中没有任何属性或值
我建议您在使用前先试用一下
当您调用数据库时,响应中有一个错误,因为您没有正确处理响应,所以出现了这个错误
要了解未定义的与其他对象值之间的差异:
let a;
let b = 22;
let c = null;
let d = {
'a': 22,
'b': [4,5,6]
};
console.log(a); // undefined
console.log(a.b); // TypeError: Cannot read property 'b' of undefined
console.log(b); // 22
console.log(b.c); // undefined
console.log(c); // null
console.log(d.a); // 22
console.log(d.b); // [4,5,6]
console.log(e); // ReferenceError: e is not defined
请添加代码:)请将代码添加为问题的内容,而不是图像链接。请添加代码:)请将代码添加为问题的内容,而不是图像链接。