Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 回调错误:TypeError:无法读取属性';行';未定义的_Node.js_Postgresql_Express_Handlebars.js - Fatal编程技术网

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

请添加代码:)请将代码添加为问题的内容,而不是图像链接。请添加代码:)请将代码添加为问题的内容,而不是图像链接。