You need to sign in to do that
Don't have an account?
NightFox
LWC - Javascript object is not reactive with Wrapper class object
HI, Could you please guide me how to make the wrapper class object reactive in LWC js.
I believe that @track properties are reactive but when I change the value of any property in `this.coreAttributes` js object, its not reflective in on `Save` button click
Js file
import { LightningElement, track, api } from "lwc"; import queryCoreAttributes from "@salesforce/apex/P1PlantInfoPromptSolar.queryCoreAttributes"; export default class P1PlantInfoPromptSolar extends LightningElement { @track coreAttributes; connectedCallback() { queryCoreAttributes() .then(result => { this.coreAttributes = JSON.parse(result); }) .catch({ }); this.promptSpecificAttributes = { noOfBlocks:"", flatHierarchy:false, drivePlus:false }; } saveP1PlantInfoPromptMetadataHandler(){ console.log(' prompt specific att -> '+ JSON.stringify(this.coreAttributes)); } }html file
<template for:each={coreAttributes} for:item="coreAttribute"> <tr key={coreAttribute.key}> <th>{coreAttribute.attributeHeader}</th> <td> <template if:false={coreAttribute.isPicklist}> <input type={coreAttribute.attributeDataType} name={coreAttribute.attributeHeader} value={coreAttribute.attributeValue}/> </template> <template if:true={coreAttribute.isPicklist}> <select size="1" name={coreAttribute.attributeHeader}> <option value="None">--None--</option> <template for:each={coreAttribute.picklistValues} for:item="attributePickValues"> <option key={coreAttribute.key} value={coreAttribute.attributeValue}>{attributePickValues}</option> </template> </select> </template> </td> </tr> <lightning-button class="slds-m-left_small" variant="brand" label="Save" title="Save" onclick={saveP1PlantInfoPromptMetadataHandler} ></lightning-button> </template>
Can you try the suggestion as mentioned in the below,
https://salesforce.stackexchange.com/questions/301273/wrapper-class-variable-show-as-undefined-in-lwc
It might help you.
https://stackoverflow.com/questions/62081474/lwc-wrapper-object-values-are-nullified-on-input-tag-value-change
Thanks
Have you found any solution for this?
i want result like this with lwc(https://rajvakati.com/2018/02/18/usage-of-lightningduallistbox/),
can anyone tell what i m doing wrong in this code below is the code
js file
import { LightningElement,track,wire,api} from 'lwc';
import getopp from '@salesforce/apex/WrapperclassForOpportunity.getopp';
export default class MultiPickList1 extends LightningElement {
@api contactlist=[];
@wire(getopp) opplist({error,data}){
if (data) {
this.contactlist = data[0].conlist;
alert('this.contactlist@@ '+ JSON.stringify (data[0].conlist) );
alert('contactlist:'+this.contactlist);
}
}
}
html file
<template>
<lightning-card title="Multi select Picklist ">
<lightning-dual-listbox
name="languages"
label="Select Record"
source-label="Available Contact Record"
selected-label="Selected Contacted Record"
options={contactlist}
onchange={handleChange}>
</lightning-dual-listbox>
</lightning-card>
</template>
wrapper class
public class WrapperclassForOpportunity {
@AuraEnabled(cacheable=true)
public static List<payWrap> getopp(){
List<payWrap> accWrapperList = new List<payWrap>();
opportunity getopp=[select id, accountid,closedate,stagename from opportunity where id=:'0062v00001TDCVoAAP'];
system.debug(getopp);
account acc= [select id, name from account where id=:getopp.accountId];
system.debug(acc);
list<contact> conlist1=new list<contact>();
conlist1=[select name from contact where accountid=:acc.id];
if(!conlist1.isEmpty()){
payWrap myWrap= new payWrap();
mywrap.conlist=conlist1;
accWrapperList.add(myWrap);
}
system.debug(accWrapperList);
return accWrapperList;
}
public class payWrap{
@AuraEnabled
public List<Contact> conlist{get;set;}
}
}