1
這是我的模型的一部分res.render與控制器響應節點玉
router.get('/subscription', function (req, res, next) {
var membership = require('../controllers/membership.js');
var jData = membership.getAll(req, res);
res.render('subscription', { title: 'Subscription', data : jData });
});
這是我controller.js的
var db = require('../db.js');
module.exports = {
//home: function (req, res, next) {
// res.send('home page');
//},
insert: function (req, res) {
var body = req.body; //_.pick(req.body, 'description', 'completed');
db.membership.create(body).then(function (membership) {
res.json(membership.toJSON());
}, function (e) {
res.status(500).json(e);
});
},
updateById: function (req, res, next) {
//var Id = parseInt(req.params.id, 10);
var body = req.body;
db.membership.update(body, { where: { id: parseInt(_.propertyOf(body)('id'), 10) } }).then(function (membership) {
if (!!membership) {
res.json(membership.toJSON());
} else {
res.status(404).send();
}
}, function (e) {
res.status(500).json(e);
});
},
deleteById: function (req, res, next) {
//var Id = parseInt(req.params.id, 10);
var body = req.body;
db.membership.destroy({ where: { id: parseInt(_.propertyOf(body)('id'), 10) } }).then(function (membership) {
if (!!membership) {
console.log('The Row with the Id : ' + _.propertyOf(body)('id') + ' deleted successfully!');
} else {
res.status(404).send();
}
}, function (e) {
res.status(500).json(e);
});
},
deleteAll: function (req, res, next) {
db.membership.truncate().then(function() {
console.log('All rows deleted successfully!');
}, function (e) {
res.status(500).json(e);
});
},
getById: function (req, res) {
var Id = parseInt(req.params.id, 10);
db.membership.findById(Id).then(function (membership) {
if (!!membership) {
console.log('\n\nMEMBERSHIP : ' + JSON.stringify(membership.toJSON()));
res.json(membership.toJSON());
//return membership.toJSON();
} else {
res.status(404).send();
}
}, function (e) {
res.status(500).send();
});
},
getAll: function (req, res) {
var where = {};
db.membership.findAll({
where: where
}).then(function (membership) {
res.json(membership.toJSON());
}, function (e) {
res.status(500).send();
});
}
};
我試圖讓AAL數據的一部分在我的模型數據來完美,所以控制器 沒有問題,但res.render函數數據無法傳遞給玉。 根據我res.render函數調用jdata變量前填充。有關它的任何解決方案都告訴我。 由於事先
謝謝這個代碼工作 –