NodeJS,分配Jade Checkbox的名称/获取值

时间:2013-02-26 07:07:10

标签: javascript node.js mobile-website pug express

我在Mongo数据库的表单中填充表格。我希望用户能够选择一个或多个复选框,然后确定从表中选择了哪些项目。问题的一部分是我不确定如何命名复选框,因为它们是动态创建的。我也不知道如何阅读复选框属性。

我正在使用ExpressJS和Jade。我可以填充表没问题,但不知道如何沟通选择了哪些项目。

这是我的玉

    h1 index view

    form  (method='post', action='/customers/check')
      fieldset
        legend Add a Customer
    div.clearfix
      -if(docs.length)
      table(style="border-left:1px solid black")
        tr
          th First Name
          th Last Name
          th "Hidden" 
            each first in docs
              tr
               td #{first.first} 
               td #{first.surname}
               td #{first.group}
               td
                 div.input
                    input(type="checkbox", name=(#{first.box}), unchecked=     (true===true ? "checked" : "")).checkbox
        div.actions
          input(type='submit', value='Save', class='btn primary')
          button(type='reset', class='btn') Cancel

我的Mongo数据库有四个属性(首先是姓氏,组和我添加的框,试图解决这个问题 在大图中我正在做的是获取一个String输入,然后用这个表渲染一个视图,我想存储String输入和从表中选择的任何元素到另一个具有两个属性的mongoDB(字符串和复杂对象)请保存meeee !!!感谢

1 个答案:

答案 0 :(得分:1)

啊得到了它,一直在解决方案中跳舞

  h1 index view

 form(method='post', action='/customers/check')
fieldset
    legend Add a Customer
    div.clearfix
        -if(docs.length)
            table(style="border-left:1px solid black")
                tr
                    th First Name
                    th Last Name
                    th "Hidden" 
                        each first in docs
                            tr
                                td #{first.first} 
                                td #{first.surname}
                                td #{first.group}
                                td
                                    div(data-role='fieldcontain')   
                                        fieldset(data-type='vertical', data-role='controlgroup')                                           
                                            label(for='showpass') show password
                                            input(id='showpass',type='checkbox', name='#{first.id}')
    div.actions
        input(type='submit', value='Save', class='btn primary')
        button(type='reset', class='btn') Cancel

和我的服务器端我将检查的值放入一个名为“arr”的数组中,这里是

     app.post('/customers/check', function(req, res) {
        console.log(req.body);
        var locks = req.body;
        var arr = Object.keys(locks);
        console.log(arr);   
        res.redirect('/customers')
});