Lightning - TypeError: this.createAppointment is not a function?

Been stuck on this for a while, cant figure out why my upsert method is not being called! Im using lightning, Can you help?

The line where i get the error is :

this.createAppointment(component, updateAppointment); 

I have used a function further up the page, which works no problem.

defaultDate: this.processDate(), //'2016-01-01', 

Helper Code

({ loadCal : function(component, appointmentsList){      var arrayLength = appointmentsList.length;     //alert(appointmentsList);     var eventsList = [];     for (var i = 0; i < arrayLength; i++) {         {             eventsList.push({                 Id: appointmentsList[i].Id,                 title: appointmentsList[i].Name,                 start: appointmentsList[i].risetest__Date__c + 'T' + appointmentsList[i].risetest__Start_Time__c + ':00',                 end: appointmentsList[i].risetest__Date__c + 'T' + appointmentsList[i].risetest__End_Time__c + ':00'             });         }     }      $('#calendar').fullCalendar({         header: {             left: 'prev,next today',             center: 'title',             right: 'month,agendaWeek ,agendaDay'         },         defaultDate: this.processDate(), //'2016-01-01',         editable: true,         eventDrop: function(event, delta, revertFunc) {             //alert(event.Id + " was dropped on " + event.start.format());             var updateAppointment ;              if (confirm("Are you sure about this change?")) {                 try {                     console.log(event);                     var tempNewDate = event.start._d;                     console.log(  tempNewDate.getFullYear() + '-' + ('0' + (tempNewDate.getMonth()+1)).slice(-2) + '-' + ('0' + tempNewDate.getDate()).slice(-2));                      var tempObject = {                         Id: event.Id,                         risetest__Date__c : tempNewDate                     }                     console.log(tempObject);                      component.set("v.appointment", tempObject);                      updateAppointment = component.get("v.appointment");                     console.log(updateAppointment);                      this.createAppointment(component, updateAppointment);                  }catch(err) {                     console.log(err);                 }             }          },         eventClick: function(calEvent, jsEvent, view) {              alert('Event: ' + calEvent.Id);          },         eventLimit: true, // allow "more" link when too many events         events: eventsList     }); },  createAppointment: function(component, appointment) { this.upsertAppointment(component, appointment, function(a) {     var Appointments = component.get("v.Appointment");   }); },  upsertAppointment : function(component, a, callback) {     var action = component.get("c.saveAppointment");     action.setParams({          "appobj": a     });     if (callback) {       action.setCallback(this, callback);     }     $A.enqueueAction(action); },  processDate : function(dt){     var MyDate = new Date();     var MyDateString;     MyDateString = MyDate.getFullYear() + '-' + ('0' + (MyDate.getMonth()+1)).slice(-2) + '-' + ('0' + MyDate.getDate()).slice(-2);     return MyDateString; } }) 

Replay

I think what is happening is an issue of scope for the This keyword. I think because you are assigning the function to the eventDrop property, this is referring to that object. Your previous use with the defaultDate did not use "this" inside another function. Try instead of using the this keyword, using

MyComponentHelper.createAppointment(component, updateAppointment);

See "As an object method": https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

Category: javascript Time: 2016-07-31 Views: 24

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.170 (s). 12 q(s)