You need to sign in to do that
Don't have an account?

LWC Collections @Track variables are read only
Basically this.caseWithComments is my track variable and it holds the list of case and using <template displaying data.
am trying to change the collection with in the JS file on button click and this.caseWithComments is read only so trying to change with new declaration and able to change the value and binding value back to the list but DOM is not rendering.
am trying to change the collection with in the JS file on button click and this.caseWithComments is read only so trying to change with new declaration and able to change the value and binding value back to the list but DOM is not rendering.
showCaseComments(event) { let caseWithCommentsNew = this.caseWithComments; //console.log('Final==='+JSON.stringify(this.caseWithComments)); for(var i=0;i < this.caseWithComments.length; i++ ){ console.log('first variable==='+JSON.stringify(this.caseWithComments[i])); let ccNew = JSON.parse(JSON.stringify(this.caseWithComments[i])); ccNew.showCComments = true; //console.log('after show comment'+ccNew.showCComments ); caseWithCommentsNew.push(ccNew); //this.caseWithComments[i] = ccNew; } //console.log('final===='+JSON.stringify(caseWithCommentsNew)); this.caseWithComments = casewithCommentsNew; console.log('length===='+this.caseWithComments.length); //this.caseWithComments.splice(1,1); console.log('Final==='+JSON.stringify(this.caseWithComments)); }
<template if:true={caseWithComments}> <template for:each={caseWithComments} for:item="cs" for:index="indexVar"> <tr key={cs.showCComments} class="slds-hint-parent"> <td><lightning-button variant="base" icon-name="utility:edit" title="Primary action" onclick={showCaseComments} > </lightning-button></td> <td > {cs.caseRecord.CaseNumber}</td> <td>{cs.caseRecord.Owner.Name}</td> <td>{cs.caseRecord.Status}</td> <td>{cs.caseRecord.CreatedDate}</td> <td>{cs.caseRecord.ClosedDate}</td> <td>{cs.caseRecord.Origin}</td> <td>{cs.caseRecord.Reason}</td> <td>{cs.caseRecord.SourceId}</td> <td>{cs.caseRecord.Description}</td> <td> <template if:true={cs.ccCount}><lightning-button variant="brand" label="Show" title="Primary action" onclick={showCaseComments} class="slds-m-left_x-small"> </lightning-button> </template></td> </tr> </template> </template>
this.caseWithComments = caseWithCommentsNew1;
All Answers
this.caseWithComments = caseWithCommentsNew1;
perfectly worked.
tried with this but it dint work and having another new one let caseWithCommentsNew1= []; working am not sure.