簡體   English   中英

無法使用此代碼編輯評論

[英]Not able to edit the comments with this code

//評論編輯路線

router.get("/campgrounds/:id/comments/:comment_id/edit", function(req,res){
Comment.findById(req.params.comment_id  , function(err,foundComment){
    if(err){
        res.redirect("back");
    } else{
        res.render("comments/edit.ejs",{campground_id :req.params.id , 
       comment:foundComment});
          }
});
});

//評論更新路線

router.put("/campgrounds/:id/comments/:comment_id",function(req,res){
Comment.findByIdAndUpdate( req.params.comment_id, req.body.comment , 
   function(err,updatedComment){
    if(err){
        res.redirect("back");
    }else{

        res.redirect("/campgrounds/" + req.params.id); 
     }

ejs文件是

  <form action="/campgrounds/<%= campground_id %>/comments/<%=comment._id%>? _method=PUT" method="POST"> <div class="container"> <input type="text" name="comment[text]" value="<%=comment.text%>"> <button>Submit</button> </div> </form> 

我也無法編輯評論或更新評論,在此先感謝:)

這是注釋模型代碼

  var mongoose= require("mongoose"); var commentSchema=new mongoose.Schema( { text: String, author: { id: { type:mongoose.Schema.Types.ObjectId, ref: "User" }, username: String } }); module.exports=mongoose.model("Comment",commentSchema); 

我認為您需要從以下位置添加一些空格:

<%=comment.text%>

<%= comment.text %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM