Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 无法调用方法';渲染';未定义的_Javascript - Fatal编程技术网

Javascript 无法调用方法';渲染';未定义的

Javascript 无法调用方法';渲染';未定义的,javascript,Javascript,我已经创建了“employees”数组,并希望使用该数组数据生成邮件。我在Node.js中为其创建了以下功能 我还创建了一个cron作业,称为以下功能。调用此函数时,会引发以下错误: 无法调用未定义的方法“render” exports.missedWorksheets = function(req, res){ var user = new User(); var dailyCurrentDate = []; var dailyCurrentDate1 = []; var

我已经创建了“employees”数组,并希望使用该数组数据生成邮件。我在Node.js中为其创建了以下功能

我还创建了一个cron作业,称为以下功能。调用此函数时,会引发以下错误:
无法调用未定义的方法“render”

exports.missedWorksheets = function(req, res){

  var user = new User();

  var dailyCurrentDate = [];
  var dailyCurrentDate1 = [];
  var missedWorkByUser = [];
  var employees = [];
  var currentDate = moment(Date.now()).format('YYYY-MM-DD');
  console.log(currentDate);
  var lastDate = moment(Date.now()).subtract(7,'days');
  var addedDate = moment(lastDate).format('YYYY-MM-DD');
  console.log(addedDate);
  for(var i=0; i<5; i++)
  {
    dailyCurrentDate[i] = moment(addedDate).format('YYYY-MM-DD');
    dailyCurrentDate[i] = moment(dailyCurrentDate[i]).add(1,'days');
    dailyCurrentDate1[i] = moment(dailyCurrentDate[i]).format('YYYY-MM-DD');
    addedDate = moment(dailyCurrentDate1[i]).format('YYYY-MM-DD');
    console.log(dailyCurrentDate1[i]);
  }

  User.find().exec(function(err, missedUsers) {
    if (err) {
      return res.status(400).send({
        message: errorHandler.getErrorMessage(err)
      });
    } else {
      Worksheet.find().populate('employee','._id').exec(function(err, missedWorksheets){
        if (err) {
          return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
          });
        }else{
          for(var i=0; i<missedUsers.length; i++){
            for(var j=0; j<missedWorksheets.length; j++){
              if(String(missedUsers[i]._id) != String(missedWorksheets[j].employee._id))
              {
                employees[i] = missedUsers[i];
              }
            }
          }
          async.waterfall([
                          function(done)
                          {
                            console.log("Async called.");
                            done(err,employees);
                          },
                          function(employees,done) {
                            console.log("Template fetch called.");
                            app.render('templates/weekly-worksheet-checking', {
                  //user: user,
                  employee: employees,
                }, function(err,emailHTML) {
                  done(err,emailHTML,employees);
                });
                          },
              // If valid email, send reset email using service
              function(emailHTML,employees, done) {
                console.log("1-mail called.");
                var mailToEmployee = config.mailer.from;
                var smtpTransport = nodemailer.createTransport(config.mailer.options);
                //users.getActiveAdminUsers(function(activeAdminUsers){
                  var receivers=mailToEmployee+',';
                // for (var i in activeAdminUsers){
                //  var activeAdminUser =   activeAdminUsers[i];
                //  receivers = receivers + activeAdminUser.email+',';
                // }
                var mailOptions = {
                  to: 'hareshr@systemintegration.in',
                  from: config.mailer.from,
                  subject: 'Unfill WorksheetList of Previous year',
                  html: emailHTML
                };
                smtpTransport.sendMail(mailOptions, function(err) {
                  if (!err) {
                    //  Notification.email = leaveResponse.employee.email;
                    //  Notification.summary = leaveResponse.leaveScheduleType;
                    //  notifications.approveLeaveNotification(req,res,Notification.email,Notification.summary);
                    res.jsonp(employees);
                  }

                  done(err);
                });
                //});
}
],function(err) {
  if (err){
    console.log(err);
    return res.send({
     message: errorHandler.getErrorMessage(err)
   });
  }
});
}
});

}
});
};
exports.missedWorksheets=函数(req,res){
var user=新用户();
var dailyCurrentDate=[];
var dailyCurrentDate1=[];
var missedWorkByUser=[];
var雇员=[];
var currentDate=时刻(Date.now()).format('YYYY-MM-DD');
console.log(当前日期);
var lastDate=时刻(Date.now())。减去(7,'days');
var addedDate=力矩(lastDate).格式('YYYY-MM-DD');
控制台日志(addedDate);

对于(var i=0;i错误说明了一切,您的
app
对象未定义。 由于您似乎在回调函数中调用了该方法,因此可能在JS代码的另一个作用域中定义了
app
对象

请查看
bind
方法

文档:

有关如何使用它的更多详细信息:

换句话说,bind()允许我们轻松地设置哪个特定对象 将在调用函数或方法时绑定到此


.render
似乎是对
应用程序的函数调用。您发布的代码没有定义
应用程序
。很抱歉,我错误地使用了“app.render”提交代码。但是我在那个地方使用了“res.render”,并且出现了相同的错误。请给我解决方案或者我错误地使用了“app.render”提交代码。但是我使用了“res.render”在那个地方出现了相同的错误。请给我解决方案