Agenda
The blog gives us a brief about how we can insert a run-time local variable in a javascript array or object and use it to do local implementations in Lightning Web Component.
What we are going to do
We are going to understand how we can insert a run-time local variable in a javascript array or object. For that, We call an apex method to fetch Account Objects records and display them over the component, and to find the serialization of the records we are going to use a run-time local variable named ‘S.NO’.
Lightning Web Component
To understand Lightning Web Component and how we can connect a Lightning Web Component to an apex class and get the relevant data. Go through ‘ Connect LWC with Apex’.
Use of local run-time variable:
Sometimes we need to display data dynamically on the client-side which is not available on the database. The local run-time data is generated at the run-time of the program and that is not getting stored anywhere. It can be different after every execution for the same record.
Scenario:
Here I am fetching records from the Account object and displaying them in the table over the component. Now we need to see the serialization of the records but the serial number is not present in the database, So, now we use a local run-time variable named ‘sNO’ to display the serial number of the records.
Expected Outcome:
Apex Class:
JavaScript:
HTML:
Resulted Outcome:
Limitations of this blog functionality:
When the apex method is called from @wire or the Apex method is annotated with @Auraenabled(cacheable = true) then the object became extensible and we can’t edit or modify them locally. This way only works when the data are fetched comparatively.
Blog’s Conclusion:
So, this blog gives us a brief that how we can use local run-time variables dynamically and how we can display them over the component. And the limitations that we this way of declaring local variables work and when not.
Thanks
COPY TO CLIP



Great explanation
ReplyDeleteThank you
Deletenicely explain great work rahul
ReplyDeleteThanks Dikshant
Delete