亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我添加數據post成功了,但是轉到詳情頁它會報錯,沒有數據顯示出來,而且數據庫沒有查到數據

//detail page
app.get("/movie/:id", function (req, res) {
? ? ? ?var id = req.params.id;

//這個id請求了2次,第二次就是偏偏unddefin,求解析

? ?console.log(req.params, id, "MOVIE/ID");
? ?Movie.findById(id, function (err, movie) {
? ? ? ?console.log(err,movie,"我我我");
? ? ? ?res.render("detail", {
? ? ? ? ? ?title: "imooc",
? ? ? ? ? ?movie: movie
? ? ? ?})
? ?})

});


//提交表單 admin post movie
app.post("/admin/movie/new", function (req, res) {
? ?var body = req.body;
? ?var id = req.body.movie._id;
? ?var movieObj = req.body.movie;
? ?console.log(body, id, movieObj, "我愛撫你");
? ?var _movie;
? ?if (id !== 'undefined') {
? ? ? ?//如果id已經存在,就用一個新的對象來替換
? ? ? ?Movie.findById(id, function (err, movie) {
? ? ? ? ? ?if (err) {
? ? ? ? ? ? ? ?console.log(err);
? ? ? ? ? ?}
? ? ? ? ? ?_movie = underscore.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
? ? ? ?});
? ? ? ?console.log(_movie);
? ? ? ?_movie.save(function (err, movie) {
? ? ? ? ? ?if (err) {
? ? ? ? ? ? ? ?console.log(err);
? ? ? ? ? ?}
? ? ? ? ? ?console.log("我愛你2 ?是")
? ? ? ? ? ?//保存成功 頁面跳轉到詳情頁面;
? ? ? ? ? ?res.redirect("/movie/" + movie._id);
? ? ? ?})
? ?}
});

正在回答

舉報

0/150
提交
取消
node+mongodb 建站攻略(一期)
  • 參與學習       91827    人
  • 解答問題       921    個

帶你完整實現一個從前端到后端的項目,初中級前端開發工程師必學課程

進入課程

為什么我添加數據post成功了,但是轉到詳情頁它會報錯,沒有數據顯示出來,而且數據庫沒有查到數據

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號