1
我有一個應用程序,我想列出一羣藝術家的信。例如,如果我輸入字母「L」 - 應用程序應將我的數據庫中的所有藝術家返回字母「L」。我對NodeJS來說很新,所以也許有人可以幫助我?NodeJS如何通過輸入具體的值來獲取數據
我routes.js:
server.get('/i/artists/:letter', myartists.getArtistByLetter);
和我artists.js:
exports.getArtistByLetter = function(req, res, next){
var where;
if(req.query == '0-9') // not sure about req.query, probably wrong???
{
where = ["formated_name RLIKE '^[0-9#]' AND artist_parent_id = 0 "];
}
else
{
where = ["formated_name LIKE '"+req.query+"%' AND artist_parent_id = 0"];
}
db.artist.findAll({
where: where,
attributes: ['artist_id', ['formated_name', 'name'], 'uuid', 'slug']
}, {raw: true})
.success(function(artist){
res.json({data: artist});
});
}
進入http://localhost:2100/i/artists/l
這將返回{"data":[]}
後...
所以,有什麼建議?謝謝...
超級!解決了它!非常感謝! :-) – Steve