我无法在express,ejs应用程序的URL中用连字符替换空格

问题描述 投票:0回答:1
I want to campname should be come with hyphens with small letters in the place sof spaces.

Actually I want only hyphens instead of spaces.

**My route:**

app.get('/:campname/edit',  adminController.getUpdateCampaign);

exports.getUpdateCampaign = (req, res) => { 
const campname = req.params.Campname;

  Campaign.findOne({campname}, (err, campaign) => {
    if(err) {
      console.log(err);
    } else {
              res.render('admin/campaign-edit', {camplist : campaign});
            }
          });

}

在ejs模板中,我如何用连字符形成UURL,该UURL与我的路线网址和连字符匹配

**front end ejs:**

 <form action="/<%=camp.Campname%>/edit" method='get'>

     <button class="btn btn-outline btn-info  dim "><i class="fa fa-edit"></i> </button>
     </form>

这个问题在前端和反手都有,我想知道几天后如何解决这个问题

node.js express ejs
1个回答
0
投票

您可以使用字符串替换方法。

<form action="/<%= camp.Campname.replace(/ /g, "-") %>/edit" method='get'>
    <button class="btn btn-outline btn-info  dim "><i class="fa fa-edit"></i> </button>
</form>
© www.soinside.com 2019 - 2024. All rights reserved.