点击录入什么反应也没有
也不报错。。。
也不报错。。。
2016-12-27
app.post('/admin/movie/new', function(req, res) {
var id = req.body.movie._id
var movieObj = req.body.movie
var _movie
if(id !== 'undefined') { //对其更新
Movie.findById(id, function(err, movie) {
if (err) {
console.log(err)
}
_movie = _.extend(movie, movieObj) //underscore
_movie.save(function(err, movie) {
if (err) {
console.log(err)
}
res.redirect('/movie/' + movie._id) //重定向
})
})
}
else {
_movie = new Movie({
doctor: movieObj.doctor,
title: movieObj.title,
country: movieObj.country,
language: movieObj.language,
year: movieObj.year,
poster: movieObj.poster,
summary: movieObj.summary,
flash: movieObj.flash
})
_movie.save(function(err, movie) {
if (err) {
console.log(err)
}
res.redirect('/movie/' + movie._id)
})
}
})
亲,在admin.jade中要写这句哦:
form.form-horizontal(method="post",action="/admin/movie/new") //重点action
还要这个哦~
app.post("/admin/movie/new", function(req, res) {
var id = req.body.movie._id;
var movieObj = req.body.movie;
// console.log(movieObj);
var _movie ;
if (id !== 'undefined') { //注意 undefined要加引号哦~~~
Movie.findById(id, function(err, movie) {
if (err) console.log(err);
_movie = _.extend(movie, movieObj);
// console.log(_movie);
_movie.save(function(err, movie) {
if (err) console.log(err);
res.redirect("/movie/" + movie._id);
});
});
}
else 。。。。。
举报