2017-04-05 13 views
0

学生のリストを示し、私は詳細ボタンをクリックしたときに問題が起こりましたstudent.jadeNode.jsのreq.bodyは次のように示す空

extends layout 

block content 
    h1 Student list 
    .studentlist 
     table 
      thead 
       tr 
        th name 
        th age 
      tbody    
       each mongo_result, i in slist 
        form(action='/detail', method="POST") 
         tr             
          td(type="text" name="name")= mongo_result.name 
          td(type="text" age="age")= mongo_result.age        
           button.btn-primary(type="submit" width='50' height='50') Detail 

app.js

app.use(express.favicon()); 
    app.use(express.logger('dev')); 
    app.use(express.json()); 
    app.use(express.urlencoded()); 
    app.use(express.methodOverride()); 
    app.use(require('stylus').middleware(path.join(__dirname, 'public'))); 
    app.use(express.static(path.join(__dirname, 'public'))); 
    app.use(app.router); 
    app.use(bodyParser.json()); 
    app.use(bodyParser.urlencoded({ extended: true })); 
    app.use(express.bodyParser()); 

app.post('/detail', (req, res) => {  
//var data = res.json({ result: result }); 
console.log(req.body); 
dbs.collection('slist').find({ name: req.body.name, age:1}).toArray((err, docs) => { 
    if (err) return console.log(err) 
    console.log(docs); 
    res.render('detail', { title: 'Detail', year: new Date().getFullYear(), message: 'Detail of student', detail: docs}); 
}); 


}) 

私は、私はまだそれのために答えを得ることはありません 他の記事からすべてのstuffsを試みたが、しています。 学生用の詳細ページを作成していますが、試してみるとreq.bodyは常に空です(各テーブルの名前と年齢はボタンをクリックすると送信されます) 私のためのアイデアはありますか? ありがとうございます。

+0

さてあなたは、ポストルートパグテンプレート内の「/詳細」を追加した場合、それは確かに動作しません、多分それはちょうどですあなたがそれを修正するまで私は本当にあなたを助けることはできません。コードはそれを見て混乱です(今すぐ) – WilomGfx

+0

post route 'detail'はapp.jsにあり、Visual Studioを使っています。 –

+0

ここでmongo_resultはどこから来たのですか?それは空ですか? – WilomGfx

答えて

0

フォームアクションには表要素が含まれていないようです。

だけ(例えばdiv要素のdiv divのよう!)テーブルの代わりにスタイルのHTMLを使用

関連する問題