1

I'm trying to convert below part of code from Aura to LWC:
Aura Code

<aura:handler name="myEvent" event="c:PPFields" action="{!c.handleEvent}" />
handleEvent(cmp, event, helper){
var wrapper = event.getParam("testWrapper");
        var object = wrapper.mapFieldApiObject;
        console.log(object);
}

I tried as the following LWC

dispatchMoveItems = (event) => {
        const passportFields = new CustomEvent('PPFields');
this.handleEvent(evnt);

        this.dispatchEvent(passportFields);
      }

handleEvent(event){
var wrapper = event.target.value;
        var object = wrapper.mapFieldApiObject;
        console.log(object);
}
```  So how could I convert above Aura handler to LWC and specifically event.getParam("testWrapper"); 
2

You event.target.value is used mainly for input elements, if you pass custom data like with aura you need to use event.detail

dispatchMoveItems = (event) => {
        const passportFields = new CustomEvent('PPFields');
this.handleEvent(evnt);

        this.dispatchEvent(passportFields);
      }

handleEvent(event){
        var wrapper = event.detail;
        var object = wrapper.mapFieldApiObject;
        console.log(object);
}
8
  • Thank you,so event.detail.testWrapper, correct? and what do you think the way that I followed to convert is correct ?
    – 3202User
    Jul 29 at 7:32
  • ye, you can put in one line event.detail.mapFieldApiObject
    – ytiq
    Jul 29 at 7:49
  • and Does converting aura:handler in Aure to CustomEvent in LWC correct?
    – 3202User
    Jul 29 at 7:51
  • 1
    yes, it's correct
    – ytiq
    Jul 29 at 7:52
  • if it answers your question please accept it
    – ytiq
    Jul 29 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.