0

Parent

Template

<lightning-button variant="brand" label="Next" onclick={FixtureType1Page}> 
</lightning-button>
<div if:true={FixtureType1flag}>
   <c-data-collection></c-data-collection>
</div>

JS I dont know what to write in Parent JS

Child

Tempalate

 <div class="slds-m-around_medium">
                <p>Technolgy Bulb Type</p>
                <template for:each={TechData} for:item="item">
                    <lightning-radio-group style="padding:6px 12px;margin:0 0 15px 
                      0;display:inline-block;"
                        value={item.value}
                        key={item.value}
                        label={item.label}
                        data-value={item.value}
                        onclick={TechDataFn}
                        variant="neutral" >
                    </lightning-radio-group >
                </template>
            </div>

js

FixtureType1Page() {
        return new Promise((resolve, reject) => {
            getTechnolgies({})
            .then(Techcnologies => {
                this.Location=Techcnologies;
                const TechTempArry = [];
                Techcnologies.forEach(function (element) {
                    let myArray = {};
                    myArray.value = element.Name
                    myArray.label = element.Technology_Bulb_Type__c
                    TechTempArry.push(myArray);
                });
                this.TechData = TechTempArry;
                console.log('TechData'+TechData);
                this.error = undefined;
                return resolve(true);

            })
            .catch(error => {
                console.log("error..ewew."+error);
                return reject(error);

            });
        //const selectedVal = this.TechBulbType;
        this.FixtureType1flag = true;
        this.Keyflag = false;

        this.selectService.classList.remove('currentFrom');
        this.selectService.classList.add('finish');
        this.dataCollection.classList.add("currentFrom");
    });
    }

So if click on button in my parent LWC then function in child lwc should call and fetch the list

1

You can send a prop value from parent component to c data collection.

<c-data-collection childvalue={parentvalue} ></c-data-collection>

define @track parentvalue inside parent.js and pass this value to child.

Now inside child.js, you have to define @api childvalue

When you click FixtureType1Page button you can update the parentvalue variable inside this function since parentvalue is tracked variable it will rerender the page and will update the childvalue inside the data collection component since child value is @api declaration

You can find more about @track and @api here

https://developer.salesforce.com/docs/component-library/documentation/en/48.0/lwc/lwc.reactivity_public

0

To make the function: FixtureType1Page() visible for parent you need to add @api decorator at begining of definition: @api FixtureType1Page() { ...

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.