我试图像上面那样动态传递查询。我有2个文本字段和提交按钮。当我点击提交按钮时,没有任何事情发生。以下是我的 app.js内容(建立数据库连接.portware_ants是数据库名称)
var mongo = require('mongodb');
var monk = require('monk');
var db = monk('localhost:27017/portware_ants');
var routes = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
//app.set('view engine', 'jade');
// Make our db accessible to our router
app.use(function(req,res,next){
req.db = db;
next();
});
app.use(' /',routes); app.use(' / users',users);
index.js文件内容
router.get('/users', function(req, res) {
var db = req.db;
var users = db.get('users');
var col_name=req.params.colname;
var col_value=req.params.colvalue;
var query={};
query[col_name]=col_value;
users.find(query,{limit: 10000},function(e, docs){
res.render('users', {
title: 'Users',
'users': docs
});
});
});
users.ejs内容(我不使用玉)
<body >
<% include partials/nav %>
<h1>Portware Orders by Symbol TCA Report</h1>
<form name="getuser",method="post",action="/users">
Column name:<br>
<input type="text" name="colname">
<br>
Column value:<br>
<input type="text" name="colvalue">
<button type="submit" value="Search" class="submitButton">Search</button>
</form>
<div id="table-scroll" >
<table align="center">
<tr style="width:200px">
<th>Symbol</th>
<th>Order_id</th>
</tr>
<% users.forEach(function(user) { %>
<tr style="width:100%">
<td ><%= user.symbol %></td>
<td><%= user.order_id %></td>
</tr>
<% }); %>
</table>
</div>
</body>
我创建了两个文本字段和一个按钮。点击按钮网址变为http://localhost:3000/users?colname=symbol&colvalue=USD%2FJPY,但我看不到过滤器正在运行。 请帮我找到问题