猫鼬,EJS,节点JS->路由不起作用

时间:2018-07-11 16:40:08

标签: node.js express mongoose ejs

任务是通过选中复选框(在每首歌曲中)并单击按钮以更改所有选中状态的状态,将所选曲目组的文件状态更改为脱机。歌曲被上传并添加到数据库。两种形式都在一张桌子下面。歌曲列表和按钮本身有不同的形式。 how the site looks

路线摘要。

app.post("/checkbox", function(req, res, next) {
console.log("route started");
var _id = req.body._id;
var group = [];
var fileStatus = req.body.fileStatus;
var dateString = new Date();
var lastChange = dateString.toDateString() + " " + dateString.getHours() + ":" + dateString.getMinutes() + ":" + dateString.getSeconds();
console.log(lastChange);
var check = req.params.check;

Mp3.find({'check': true}, function(err, result) {
    if (err) throw err;
    group.push(result);

    group.forEach(function(err, result){
        if (err){
            console.log(err);
        } else {
            Mp3.update({_id: req.body._id}, {$set: {fileStatus:"offline", lastChange: lastChange}}, function(err, updated){
                if(err){
                console.log(err);
                } else{
            res.redirect("/database");
    }
  });
 }

});

});

html表单的片段。

<form action="/checkbox" method="POST" onsubmit="return confirm('Click OK to confirm or cancel to abort.');">
           <input type="submit" id="group_offline" name="group_offline" value="Change to offline">
        </form> 

复选框表单的片段。

 <form action="/checked" method="POST">
            <input type="checkbox" class="check" id="check" name="check" value="<%= mp3file.check%>" unchecked>
             <!--<input type="submit" id="group_offline" name="group_offline" value="Change to offline">-->
          </form>

0 个答案:

没有答案
相关问题