0
<template for:each={openCases.data} for:item="cs">
 <span key={cs.Id}> {cs.Title__c} on {caseName} </span>
</template>

JS:

    @wire(getCaseList, { Id: '$caseId' }) openCases;
    get caseName(){
     console.log(JSON.stringify(this.openCases));
     //above log returns the data
     /*{"data":[{"Id":"b6m3C000000LGQuQAO","Title__c":"Unable to Login","Account__r":{"Name":"","Id":"j6o3C0000004N67QAE"}}]}*/

          // returns Cannot read property 'Title__c' of undefined
       console.log(this.openCases.data.fields.Title__c.value);


    }

Can some help me on why the property values are being returned undefined although I'm able to see that property has been defined?

1 Answer 1

2

It seems like it is returning an array with a length of 1 for data. So you would have to do:

this.openCases.data[0].Title__c
4
  • ah, I totally didn't see that I was looping through. I see that there is for:index="index" on for each, how do I pass the index to JS. Thanks!
    – cartman
    Nov 20, 2019 at 21:55
  • Not sure I understand, are your trying to construct the case name in JS? Can you just not call it directly in your span tag? Nov 20, 2019 at 22:02
  • Yes,my question was how to pass index on to component. I have too many if conditions and I believe it would easier returning the values at JS level.
    – cartman
    Nov 21, 2019 at 17:16
  • So there is a for:index attribute, however, I don't know if there is a way to pass an iteration of a for:each to a JS method (i.e. {jsFunc(ind)}) Nov 21, 2019 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .