extend返回不对,以及save方法不存在
1.extend调用的时候返回值有问题
使用方案1的时候,extend返回的结果,movie,_movie值都不对
改用方案2的时候,返回的结果_movie与movieObj一样,都是json结构的值
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 = new Movie() console.log('movie') console.log(movie) console.log('_movie') console.log(_movie) _movie = _.extend(movie, movieObj) //方案1 _movie = _.extend({}, movieObj) //方案2 console.log('movieobj') console.log(movieObj) console.log('movie') console.log(movie) console.log('_movie') console.log(_movie) _movie.save(function(err, movie){ if(err){ console.log(err) } res.redirect('/movie/' + movie._id) }) }) } else{ _movie = new Movie({ director: movieObj.director, 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) }) } })
2.采用方案2之后,调用的save方法有问题
imooc started on port 3000
movie
null
_movie
undefined
movieobj
{ title: '机械战警007',
director: '若泽·帕迪里亚',
country: 'America',
language: 'English',
poster: 'http://img5.douban.com/view/movie_poster_cover/spst/public/p2170735207.jpg',
flash: 'http://player.youku.com/player.php/sid/XNjMyMTkzODcy/v.swf',
year: '2014',
summary: 'gggggggggggggggggggggggggggggggggggggggggggg' }
movie
null
_movie
{ title: '机械战警007',
director: '若泽·帕迪里亚',
country: 'America',
language: 'English',
poster: 'http://img5.douban.com/view/movie_poster_cover/spst/public/p2170735207.jpg',
flash: 'http://player.youku.com/player.php/sid/XNjMyMTkzODcy/v.swf',
year: '2014',
summary: 'gggggggggggggggggggggggggggggggggggggggggggg' }
/home/lee/imooc/app.js:98
_movie.save(function(err, movie){
^
TypeError: Object #<Object> has no method 'save'