1
我送查詢參數爲JSON格式req.query.p
從我的前端MVC框架,問題是,這可能是一個動態密鑰和值,例如:sequelize動態查詢參數
req.query.p = {nombre : 'juan'}
或
req.query.p = {pais : 'chile'}
所以我需要鑰匙,和值將它們放在where語句,像這樣
exports.select = function(req, res){
console.log('=> GET | Obtener peliculas'.bold.get);
db.Pelicula
.findAndCountAll({
limit : req.query.limit,
offset : req.query.offset,
where : req.query.p ? [req.query.p.KEY + " = ?", req.query.p.VAL] : null
})
.success(function(resp){
console.log(JSON.stringify(resp.rows, null, 4).bold.get);
res.json({peliculas : resp.rows, meta : { total : resp.count}});
});
}
謝謝!它的作品:P。順便說一句,如果我想傳遞多個參數給我的查詢呢?哪個是正確的方法來處理這個問題? – jFranciscov 2014-09-29 18:32:48
'其中:{arg1:something,arg2:somethingelse}' - 普通的舊javascript對象 – 2014-09-30 07:23:12
那裏有什麼操作? 「...其中arg1 =某事AND/OR?arg2 = somethingelse」 – jFranciscov 2014-09-30 11:52:49