I'm hoping I got the right area to ask for this...
Below is some code from two files I'm working on. When I change anything with 'this.
' in the function to an arrow function, the code no longer functions as expected.
Is someone able to explain what I'm doing wrong? Do I need to do something differently when using arrow functions? Am I using 'this.' incorrectly to begin with? Should I not be using arrow functions in this way?
Help is greatly appreciated.
client/views/jobList.html
{{#each jobs}}
<tr>
<td>{{jobID}}</td>
<td>{{user.fullname}}</td>
<td>{{product.type}}</td>
<td>{{shortDesc}}</td>
<td>{{formattedDate}}</td>
<td>{{phone}}</td>
<td>{{user.username}}</td>
<td>{{jobType}}</td>
<td>{{product.brand}}</td>
<td>{{product.type}}</td>
<td>{{product.model}}</td>
</tr>
{{/each}}
client/views/jobList.js
Template.jobList.helpers({
jobs: ()=> Jobs.find({}, {sort: {jobDate: 1}}),
formattedDate: function() { // Changing this to arrow function breaks functionality
let d = this.jobDate;
let e = formatDate(d);
return e;
},
shortDesc: function () { // Changing this to arrow function breaks functionality
if (this.description.length > 40) {
return this.description.substr(0, 50) + '...';
} else {
return this.description
}
},
jobID: function () { // Changing this to arrow function breaks functionality
let a = this.jobNum;
let e = this.jobType.substr(0, 1);
return e + a
}
});