想进行动态查询,在该查询中将根据匹配结果的urlSearchParams数据返回数据。它应该从数据库返回数据,其中键和值与urlSearchParams匹配,例如与所有Year(2019年和2018年)等等。
基于urlSearchParams的动态数据,如何使其能够查询并返回urlSearchParams中匹配的数据({'Year'=>'2019,2018','Make'=>'Acura,BMW' })
q.where(urlSearchParams key should be here).in([urlSearchParams]);
{ 'Year' => '2019,2018', 'Make' => 'Acura,BMW' }
view.on('init', function (next) {
var q = keystone.list('Post').paginate({
page: req.query.page || 1,
perPage: 2,
maxPages: 2,
filters: {
state: 'published',
},
})
.sort('-publishedDate')
.populate('author categories');
if (locals.data.category) {
//Where key is in urlSearchParams for example based on this searchparams
{ 'Year' => '2019,2018', 'Make' => 'Acura,BMW' }
It should return the data from the database where Key and values that matches from urlSearchParams
like all the Year which is 2019 and 2018 so on and so forth
q.where('Key Here ').in([urlSearchParams]);
}
q.exec(function (err, results) {
locals.data.posts = results;
next(err);
});
});