I'm trying to implement a sorting function for the records returned by a callback. The normal javascript a.value - b.value
inline implementation is working. This is the working code that I have:
/aura/myComponent/myComponentHelper
$A.getCallback(function(result) {
var cases = result.values.cases;
cases.sort(function (a, b) {
return b.CaseNumber - a.CaseNumber
})
})
I wanted to make a separate function out of this inline function, so I did a function like this:
/aura/myComponent/myComponentHelper
getCases : function (component) {
var self = this;
... other codes...
myPromise.then (
$A.getCallback(function(result) {
var cases = result.values.cases;
cases.sort(self.sortByCaseNumber());
... other codes ...
})
)
.catch (
... other codes ...
)
},
sortByCaseNumber : function(a, b) {
return b.CaseNumber - a.CaseNumber
}
However, I'm encountering an Error in $A.getCallback() [Cannot read property 'CaseNumber' of undefined]
.
Inside the sortByCaseNumber function, the values of a
and b
are both undefined. Not sure why this is happening. I'm checking the values of the cases
list right before I sort it and the list definitely contains an array of case objects, and the CaseNumber field is there.
sortByCaseNumber(a,b)
function?