【发布时间】:2020-09-01 22:04:58
【问题描述】:
如果我使用 RegExp,那么我的搜索小部件页面总是会得到: /(?:)/i
因此总是加载结果列表。我不希望这种情况发生。我只想加载我的页面,然后用户填写搜索框,然后执行 GET 请求。
app.get("/la_widget", function(req, res) {
var test = new RegExp(req.query.search, 'i');
console.log(test);
Restaurant.find({
LocalAuthorityName: test
},
null,
{
limit: 50
},
function(err, foundAuthority) {
if (foundAuthority) {
res.render("la_widget", {foundAuthority})
} else {
res.render("la_widget", "No local authority matching that input was found.");
}
});
});
【问题讨论】:
-
允许用户输入定义正则表达式是不明智的*
-
@LawrenceCherone 感谢您的评论,我想了解更多有关执行此操作的最佳方法的信息。请问你有一个例子或一些额外的信息吗?当我更改数据库或向我的 MongoDb 添加额外文档时,在我填写搜索框并点击“搜索”按钮之前,我经常会再次出现这个问题,即自动搜索启动。
标签: node.js forms express get xregexp