如何根据其他选择创建过滤器下拉列表



我想在EJS的另一个选择上创建过滤器下拉列表,这两个列表都来自Mongo数据库。我应该做什么?我索要节点JS

<label>Gender</label>
<select placeholder="Enter Your Gender">
  <option selected>Select Your Gender</option>
  <option>Male</option>
  <option>Female</option>
</select>
<label>Title </label>
<select name="title" placeholder="Enter Your Title">
  <%for(let t of title){%> //we can write(var ms = 0;ms< status.length; i++)instead of (let ms of maritalstatus)
  <option value="<%= t.male_english%>"><%= t.male_english%></option>
  <%}%>
</select>

app.js

app.get('/data-en', function(req, res, next) {
  let data = {} // data will send to page
  // get data from database
  db.collection('religious_category').find({}).toArray().then(religious => {
    data.religious = religious
    db.collection('list_of_marital_status').find({}).toArray().then(maritalstatus => {
      data.maritalstatus = maritalstatus
      db.collection('list_of_countries').find({}).toArray().then(countries => {
        data.countries = countries
        db.collection('honorifi_Title').find({}).toArray().then(title => {
          data.title = title
          res.render('data-en', data) // at the end
        })
      })
    })
  })
})
app.post('/data-en', (req, res, next) => {
  db.collection('newperson-en').insertOne(req.body, () => {
    res.redirect('/data-en')
  })
})

我在数据库中有男性和女性的数据列表我想要按性别按作为男性的标题名单时出现男性标题和vice

您将一个名为data的对象传递给模板,而您正在尝试访问一个名为title的对象。

您必须将对象的属性直接传递到模板:

res.render('data-en', {
        title: data.title,
        religious: data.religious,
        maritalstatus: data.maritalstatus,
        countries: data.countries
    });

最新更新