0

I'm trying to fire an Lightning Application event from a d3.js handler. Basically I'm doing following:

let stageMenuSelection = stageMenuContainer.select(stageMenuSelector),
        stageElementSelection = stageMenuContainer.selectAll(opportunityStageItemSelector),
        event = window.$A.get("e.SFVisionLDV:PageSetEvent"),
        context = this;

After defining stageMenuContainer I iterate over it:

stageElementSelection
        .each(function(item) {
            console.log("stageMenu update this")
            console.log(this);
            let opportunityStageItem = d3.select(this);

on finally I define the click event:

opportunityStageItem.on('click', function() {
                console.log("stageMenu update opportunityStageItem click")
                    let stageElementItem = d3.select(this),
                        selectedStage = stageElementItem.attr('data-role'),
                        recordId = stageMenuSelection.attr('data-recordid'),
                        data = {recordId: recordId, stage: selectedStage};
                    console.log("stageMenu update opportunityStageItem click selectedStage");
                    console.log(selectedStage);
                    console.log("stageMenu update opportunityStageItem click recordId");
                    console.log(recordId);
                    console.log("stageMenu update opportunityStageItem click data");
                    console.log(data);
                    console.log("stageMenu update() event again")
                    console.log(event);
                    context.dispatchOpportunityStageEvent(data);

where dispatchOpportunityStageEvent is defined as:

dispatchOpportunityStageEvent(data){
    console.log("stageMenu dispatchOpportunityStageEvent()")
    console.log(window.$A);
    if(window.$A){
        window.$A.getCallback(function() {
            var event = window.$A.get("e.SFVisionLDV:PageSetEvent");
            console.log("stageMenu dispatchOpportunityStageEvent() event")
            console.log(event);
            if (event) {
                let context = this;
                console.log(context);
                event.setParams(data);
                event.fire();
            }
        })
    }
}

As stated here I already tried to put in different places the window.$A.getCallback() and also read the docs in Modifying Components Outside the Framework Lifecycle. I'm not sure what I'm doing wrong.

Your Answer

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

Browse other questions tagged or ask your own question.