You need to sign in to do that
Don't have an account?
George Galaios 12
LWC - Listener for changes of a property with multiple attributes
I am new to Javascript and LWC so this question might be very easy! But i can't find a way to implement it... For the time being, i have a listener that when a value of a variable changes, it handles the change. Now, i want to take it one step further... I want to put 2 more properties to this variable and have it to the listener. Is this possible ?? A code snippet until now:
Now i want to make it somehow like this:
How could i implement my listener since it has just three inputs? (Target, key, value.) Is it possible to add more arguments? Also, how could i modify my listener method? Thanks!
/* @ggalaios 07/04/2020 */ import { LightningElement, wire, track, api } from "lwc"; import { loadScript, loadStyle } from "lightning/platformResourceLoader"; //In order for fullCalendar to be displayed import FullCalendarJS from "@salesforce/resourceUrl/FullCalendarJS"; //import the static Resource! import { NavigationMixin } from "lightning/navigation"; //Import this in order to be able to pop-up the New Event Screen import { encodeDefaultFieldValues } from "lightning/pageReferenceUtils"; import getMyEvents from "@salesforce/apex/fullCalendarController.getEventsForCurrentUser"; //in order to call fullCalendarController Apex Class import { RecordFieldDataType } from "lightning/uiRecordApi"; export default class FullCalendarJs extends NavigationMixin(LightningElement) { @wire(getMyEvents) myEvents; //@wire is used to call automatically the Apex method! @track eventsList = []; currentEvent; @track eventView = { value: "timeGridWeek" }; connectedCallback() { var targetProxy = new Proxy(this.eventView, { set: (target, key, value) => { alert(`${key} set to ${value}`); target[key] = value; const viewChangeEvent = new CustomEvent("viewchange", { detail: { data: target[key] } }); // Fire the custom event this.dispatchEvent(viewChangeEvent); return true; } }); this.eventView = targetProxy; } }
Now i want to make it somehow like this:
@track eventView = { value: "timeGridWeek", startDate: "08/04/2020", endDate: "15/04/2020" };
How could i implement my listener since it has just three inputs? (Target, key, value.) Is it possible to add more arguments? Also, how could i modify my listener method? Thanks!
David Zhu 🔥
I will create a child component containing three fields in eventView property. In the child component, an event is fired when any of the fields changing value. In the parent componet, a method is to handle the value changes.
George Galaios 12
I solved the issue by adding 3 more variables. I post my code so that maybe someone could be helped in the future: