NodeJS用sequelize发布数据

时间:2018-05-03 21:54:42

标签: javascript node.js express sqlite sequelize.js

我正在开发一个假冒图书馆数据库和网站界面的项目。目前,4个新贷款表单输入中只有2个被传递给req.body。所有项目都有一个名称属性,但只有输入字段通过,而select / option字段不是。任何帮助是极大的赞赏!项目信息和所有其他项目文件的链接都在GitHub上。 Here is the link to GitHub



const
        express         = require("express"),
        app             = express(),
        path            = require("path"),
        cookieParser    = require("cookie-parser"),
        bodyParser      = require("body-parser"),
        routes          = require("./routes/index");

//Setting Up
//  Pug as the view engine, bodyParser, and cookieParser
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use('/static', express.static('public'));

const
    express = require("express"),
    router  = express.Router();
    Books   = require("../models").Books;
    Loans   = require("../models").loans;
    Patrons = require("../models").patrons;

router.post('/newloan', (req, res, next) => {
  Loans.create(req.body).then((loan)=>{
    console.log('/////////////////////////////////////////');
    console.log(req.body);
    console.log('/////////////////////////////////////////');
    res.redirect('/allloans');
  });
});

extends ../layout

block content
    h1= title
    form( method="POST" action="/newloan")
        p
            label(for='book_id') Book
            select#book_id
                each book in books
                    option(value=book.id name="book_id")= book.title
        p
            label(for='patron_id') Patron
            select#patron_id
                each patron in patrons
                    option(value=patron.id name="patron_id") #{patron.first_name} #{patron.last_name}
        p
            label(for='loaned_on') Loaned on:
            input#loaned_on(type='date' name="loaned_on" value=loan.loaned_on)
        p
            label(for='return_by') Return by:
            input#return_by(type='date' name="return_by" value=loan.return_by)
        p
            input(type='submit' value='Create New Loan')




1 个答案:

答案 0 :(得分:1)

您没有提供选择框的名称,以下内容可能会对您有所帮助

extends ../layout

block content
    h1= title
    form( method="POST" action="/newloan")
        p
            label(for='book_id') Book
            select#book_id(name="book_id")
                each book in books
                    option(value=book.id)= book.title
        p
            label(for='patron_id') Patron
            select#patron_id(name="patron_id")
                each patron in patrons
                    option(value=patron.id) #{patron.first_name} #{patron.last_name}
        p
            label(for='loaned_on') Loaned on:
            input#loaned_on(type='date' name="loaned_on" value=loan.loaned_on)
        p
            label(for='return_by') Return by:
            input#return_by(type='date' name="return_by" value=loan.return_by)
        p
            input(type='submit' value='Create New Loan')