I have the following properties in an lwc component:
editPropertiesMap = new Map(); editPropertiesView = []; I have a function that edits values in editPropertiesMap, and at the end runs the following:
this.editPropertiesView = [...this.editPropertiesMap].map(([key, value]) => ({ key, value })); This is how its used in HTML:
<template> <lightning-layout multiple-rows pull-to-boundary="small"> <template if:true={editPropertiesView}> <template for:each={editPropertiesView} for:item="prop"> <template if:true={prop.value.availableForEdit}> <lightning-layout-item size="12" key={prop.key}> <c-edit-property obj={prop.value}></c-edit-property> </lightning-layout-item> </template> </template> </template> </lightning-layout> </template> The child components simply contains @api obj and it shows the values in some text box.
Every time i update editPropertiesView, i excpet the html to be re-rendered and that all of the child components will use the new values.
However, the values are not changed and i have no idea why.
Child component:
@api obj; @track currentObj; connectedCallback() { this.currentObj = JSON.parse(JSON.stringify(this.obj)); } HTML:
<template> <lightning-layout> <template if:true={currentObj}> <lightning-layout-item size={currentObj.size} padding="around-small" class="paddingEditPanel"> <lightning-input data-id={id} date-style="short" type={currentObj.type} value={currentObj.value} checked={currentObj.value} label={currentObj.label} onchange={handleInputChange} disabled={isDisabled}> </lightning-input> </lightning-layout-item> </template> </lightning-layout> </template> Based on some suggestions i googled:
- i tried to add
@track - i tried do a shallow copy like this:
this.editPropertiesView = [...this.editPropertiesView]
nothing works, please advise.