如何根据复选框条件删除多行

问题描述 投票:0回答:1

我是node.js的新手。我创建了一个小示例,现在我想根据复选框条件删除多行。我有一个复选框表作为最后一列。我要在单击按钮时删除选中的复选框行。

玉码是

<section class="get">
<h3>Get Data</h3>
<a href="/get-data">LOAD DATA</a>
<div>
    <table>

    {{# each items }}
        <article class="item">
            <tr>
            <td>{{ this.title }}</td>
            <td>{{ this.content }}</td>
            <td>{{ this.author }}</td>
            <td>{{ this._id }}</td>
           <form action="/check" method="post">
           <td><input type="checkbox" id="chk" name="chk" ></td>

        </article>
        </tr>
    {{/each}}
    <button>check</button>
           </form>
    </table>
</td>
</section>

后端代码是

router.get('/get-data', function(req, res, next) {
    var resultArray = [];

    mongo.connect(url, function(err, db) {
        assert.equal(null, err);
        var cursor = db.collection('user-data').find();
        cursor.forEach(function(doc, err) {
            assert.equal(null, err);
            resultArray.push(doc);
        }, function() {
            db.close();
            res.render('index', {items: resultArray});
        });
    });
});`


router.post('/check', function(req, res, next) {
// var id = req.body.id;
    console.log("check value");
    console.log(req.body.chk);
    req.body.chk=Boolean(req.body.chk);
    for(i=0; i<req.body.chk;i++){
        if(req.body.chk==true){
            res.redirect('/');
        }
        else{
            res.send("checkbox is not checked");
        }
    }
});   
node.js mongodb pug
1个回答
0
投票

在这种情况下,Jade计划单独更新每个记录。如果我要进行更正并立即更新所有已编辑的记录。 Express&mongo怎么可能

© www.soinside.com 2019 - 2024. All rights reserved.