2017-08-15 72 views
0

我正在嘗試在帕格代碼中創建一個「每個」,但運行該應用程序後,出現「無法讀取屬性'長度'的未定義」錯誤。無法讀取帕格/玉器中的屬性'長度'

這是我的哈巴狗模板代碼:

extends ../templates/default 

block content 
    - var item = []; 
    form.post(action='http://localhost:3000/users/panel', method='post') 
    img.avatar(src='/img/avatar.jpg', alt='') 
    input(type='text', name='post', value='', placeholder='Escribe algo') 
    input(type='submit', value='Publicar') 
    #card-container 
    .card 
     img.avatar(src='/img/avatar.jpg', alt='') 
     .name='@'+user.nombre 
     .date='id='+user.id 
     p.card='Hi!' 
    table 
    thead 
     tr 
     th # pub 
     th # user 
     th Publicacion 
    tbody 
     each item in items 
     tr 
      td=item.id_publicacion 
      td=item.id_user 
      td=item.publicacion 

這是我的控制器:

getPubs: function(req, res, next) { 
    var config = require('.././database/config'); 
    var db = mysql.createConnection(config); 

    db.query('SELECT * FROM publicaciones', function(err, rows, fields) { 
     res.render('panel', { 
      items: rows 
     }); 
    }); 
} 

最後是這樣的路由器(如我打這個電話):

router.get('/users/pubs', controllers.UserController.getPubs); 

回答

0

您在渲染調用「面板」,但它看起來就像是爲「用戶」,所以你必須把這個:

getPubs: function(req, res, next) { 
    var config =require('.././database/config'); 
    var db = mysql.createConnection(config); 

    db.query('SELECT * FROM publicaciones', function(err, rows, fields) { 
     res.render('users/panel', { 
      items: rows 
     }); 
    }); 
} 
0

我想你的mysql連接有錯誤。您可以添加錯誤處理程序到您的CONTROLER這樣的:

getPubs: function(req, res, next) { 
    var config =require('.././database/config'); 
    var db = mysql.createConnection(config); 

    db.query('SELECT * FROM publicaciones', function(err, rows, fields) 
{ 
    if (err) { 
     console.log(err); 
     return res.status(500).send({err: err}); 
    } 

    res.render('panel', { 
     items: rows 
    }); 
}); 
} 
相關問題