简体   繁体   English

通过Node.Js禁用按钮

[英]Disable Button by Node.Js

i need to Disable a Button using Node.js and Express. 我需要使用Node.js和Express禁用按钮。 My code looks like this. 我的代码如下所示。

    // ITEM SECTION =========================
app.get('/item/:id', function(req, res) {

    Listing.findOne({'_id': req.params.id}, function(err,products){

        res.render('item.ejs', {
            products: products,
            user : req.user

        });
    });
});

I want to disable the Button if the user already clicked it and added the Product to his Favorite list or if the User is the owner of this Product. 如果用户已经单击按钮并将产品添加到“收藏夹”列表中,或者用户是该产品的所有者,我想禁用该按钮。

My Schema: 我的架构:

var Listing = mongoose.Schema({

product            : {
    ownerid     : String,
    name        : String,
    desc        : String,
    price       : Number,
    imagename   : String,
    interessteduser :  [ mongoose.ObjectId ]

} });

How can i do this? 我怎样才能做到这一点? Do i need to grab all "interessteduser" and loop them trough the req.user? 我是否需要抓住所有“ interessteduser”并将其循环通过req.user?

You can store the id of the user in your scheme (user_click_id - property) who click on the button. 您可以将用户的ID存储在单击该按钮的方案中(user_click_id-属性)。
And when he came to the page send check his click. 当他来到页面时,发送检查他的点击。

app.get('/item-check/:id', function(req, res) {
Listing.find({'user_click_id': {$contains : req.params.id}}, function(err,users){
    res.send({'disable': users.length ?  false: true})   
});

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM