湂劊: express坺獙,mongodbä¸ćˇťĺŠ 莰录,ä¸?䟚进兼saveĺ›žč°ƒ.
ćœ€čż‘ĺœ¨ĺŚexpress坺獙,写了一个甾役网獙的demo,é ‡ĺˆ°ä¸€ç‚šé—Žé˘˜,癞ć€?ä¸?垗兜解,ćą‚ĺ¤§çĽžćŒ‡ç‚š.
é—Žé˘˜ć??čż°:
ĺœ¨ć–°ĺ˘žčŽ°ĺ˝•çš„ć—śĺ€™,襨ĺ?•ĺĄŤĺ†™ĺŽŒćˆ?炚凝察兼,诡湂ĺ?‘é€ ĺ‡şĺŽťäş†,ä˝†ć˜ŻĺŽƒäźšä¸€ç›´čŻˇćą‚,ä¸?䟚进兼saveĺ›žč°ƒ,äšŸć˛Ąćœ‰ćŠĽé”™.(čż™é‡Œčż›çš„ć˜Żifä¸elseéƒ¨ĺˆ†çš„äťŁç ĺ?—)
app.post('/admin/movie/new', function (res, req) {
var id = res.body.movie._id;
var movieObj = res.body.movie;
var _movie;
if (id !== 'undefined') {
Movie.findById(id, function (err, movie) {
if (err) {
console.log(err);
}
_movie = _.extend(movie, movieObj);
_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);
});
}
});
éĄšç›Žĺœ°ĺ?€: https://github.com/xjchenhao/Learn/tree/master/nodejs/%E7%AB%99%E7%82%B9%E5%BB%BA%E8%AE%BE/imooc
传说D裤子
9 years, 10 months ago