2013-02-26 43 views
2

我在Mongo數據庫的表單中填充表格。我希望用戶能夠選擇一個或多個複選框,然後確定從表格中選擇了哪些項目。問題的一個部分是我不確定如何命名複選框,因爲它們是動態創建的。我也不知道如何閱讀複選框屬性。NodeJS,指定Jade複選框的名稱/獲取值

我正在使用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的數據庫具有四個屬性(第一,姓,組,我在試圖解決這個問題 在大圖什麼,我做的是一個添加盒字符串輸入,然後渲染一個視圖與這張表,我想存儲的字符串輸入和表中的任何元素被選中到另一個mongoDB與兩個屬性(字符串和複雜的對象)請saveee meeee !!!謝謝

回答

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 

和我的服務器端我把檢查的值成所謂的「改編」的數組,這裏是

 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') 
});