我有两种形式,我可以同时点击一个按钮。 问题是,只有第二个表单输入被写入数据库。 它总是第二种形式。我试图改变submit()调用的顺序,并始终将第二个调用表单的输入写入数据库。 有什么建议吗?
保存方法:
app.post('/saveInScopeStatuses', function (req, res) {
var db = req.db;
var scopes = req.body.scope;
var collection = db.get('scopestatuses');
var total = scopes.length;
for (var i = 0; i<total; i++){
var scope = scopes.pop();
collection.update({"status": {
$eq: scope}
}, {
$set: {
inscope: true
}
},
{upsert: true});
}
});
app.post('/saveOutScopeStatuses', function (req, res) {
var db = req.db;
var scopes = req.body.scope;
var collection = db.get('scopestatuses');
var total = scopes.length;
for (var i = 0; i<total; i++){
var scope = scopes.pop();
collection.update({"status": {
$eq: scope}
}, {
$set: {
inscope: false
}
},
{upsert: true});
}
});
形式:
<form id="inScopeForm" method="post" action="saveInScopeStatuses">
{{#each scopes}}
{{#if status}}
<input type="hidden" name="scope" value=" {{status}}"/>
{{/if}}
{{/each}}
</form>
<form id="outScopeForm" method="post" action="saveOutScopeStatuses">
{{#each scopes}}
{{#unless status}}
<input type="hidden" name="scope" value="{{status}}"/>
{{/unless}}
{{/each}}
</form>