SELECT始终在输入文本中显示undefined
路线:
exports.edit = function(req, res){
var id =(req.params.id);
customer = db.getCustomerById(id,function(results){
res.render('customer/edit', {customer: results });
});
};
数据库功能:
exports.getCustomerById = function(id,callback){
var objBD = BD();
objBD.query('SELECT * FROM user WHERE id=? ', id, callback);
};
Edit.jade:
form(id='form', method='POST', action='/customer/edit/#{customer.id}')
input(type='text', id='name', name='name' value='#{customer.name}')
input(type='email', id='email', name='email' value='#{customer.email}')
input(type='tel', id='phone', name='telephone' value='#{customer.phone}')
答案 0 :(得分:1)
您在db.getCustomerById
中传递的回调应采用格式callback(err, results
)。我想results
参数将是一个数组,所以要挑选客户,你需要做customer = results[0]
。
请尝试以下代码:
exports.edit = function(req, res){
var id =(req.params.id);
customer = db.getCustomerById(id,function(err, results){
if (err) {
console.log("Ops! Error trying to get customer ....");
throw err;
}
res.render('customer/edit', {customer: results[0] });
});
};