使用自定义猫鼬方法创建日期数组

我想在用户输入开始日期和结束日期之后创建日期数组。

我为自己的架构创建了一个方法,该方法将采用开始和结束日期,然后生成日期数组。

架构

 const monthSchema = new mongoose.Schema({
 startDate: Date,endDate: Date,dateArray: Array
 });

monthSchema.methods.createDateArray = function(start,end) {
const dateArray = [];
end.setDate(end.getDate() +1);

 while (start < end) {
   let newStart = new Date(start);
   newStart.setDate(newStart.getDate() + 1)

   dateArray.push(newStart);
   start.setDate(start.getDate() + 1)
 }

   return dateArray;
};

const Month = mongoose.model("Month",monthSchema);

EJS文件

<div class="modal-content">
   <span class="close" >Close &times; </span><br>
   <form action="/addmonth" method="post">
 Date:<br>
 Start Date
<input type="date" required pattern="\y{4}-\d{2}-\d{2}" name="startDate"> 
 <br>
 End Date
 <input type="date" required pattern="\y{4}-\d{2}-\d{2}" name="endDate"> 
 <br>
 <input type="submit">
</form> 

app.js

app.post("/addmonth",function(req,res){

  const month = new Month({
  startDate: req.body.startDate,endDate: req.body.endDate,dateArray: createDateArray(starteDate,endDate)

  });  

   month.save(function(err){
   console.log(month);
   if (!err){
     res.redirect("/admin");
    }
  });
});

此行返回错误:

 dateArray: createDateArray(starteDate,endDate)

错误:

  

ReferenceError:未定义createDateArray

我不确定在用户输入日期后如何用我的方法创建数组。任何帮助将不胜感激。

b_bunny 回答:使用自定义猫鼬方法创建日期数组

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3127848.html

大家都在问