@track in Lightning Web Components
Did you know that you can pass complex types of data from Lightning Web Components to Apex controllers?
I've recently implemented a Lightning data table with pagination and sorting so I've created a data structure "queryParameters" like this (*):
@track queryParameters = {
sortFieldName: '', sortDirection: '', pageNumber: 1, pageSize: 8
};
Then I've referenced the queryParameters variable in a @wire call to an Apex controller as below:
@wire( getAvailableRecords, { queryParameters: '$queryParameters' } )
Then found a couple of interesting details:
领英推荐
So I've ended up coding the changes to queryParameters like below, to cause @track to not ignore changes:
// refresh data when page is changed
this.queryParameters = {
...this.queryParameters
, pageNumber: pageNumber
};
...
// refresh data when sorting criteria is changed
this.queryParameters = {
...this.queryParameters
, sortFieldName: fieldName
, sortDirection: sortDirection
}
(*) @track is no longer needed since Spring '20 release and all fields in a LWC class are reactive. @track was mentioned to make the point clear.
It is interesting though that the observed behavior is exactly opposite of what is described in Spring '20 and has been reported as a bug.
Application Development Team Lead ( Salesforce )
2 年The other way is - pass json string from lwc and deserialize it on Apex side ??
Senior Salesforce Administrator at Enpal B.V | Salesforce Professional | Trailhead Mentor
2 年Hi Fernando F. can you share the Article please, I want to go through it..