0

I'm trying to show or not show the content of field in a data table depending on if it is null or empty etc. What am I doing wrong?

<th scope="col"> <div lwc:if={isNotes}> <a href="#" data-id={task.Id} onclick={clickViewTask} data-index={index}>{task.Name} Notes </a> </div> </th> 
LWC .js @wire(getList, { retId: '$recordId'}) //a3Z8K000001bxakUAA contactRec(result) { this.taskResult = result; if(result.error){ console.log('error is#'+result.error); this.error = result.error; } else if(result.data){ this.lsttasklist = result.data; let tempArray = []; for(let i=0; i<this.lsttasklist.length; i++) { tempArray.push({Id:this.lsttasklist[i].Id, Owner_Name__c:this.lsttasklist[i].Owner_Name__c, Name:this.lsttasklist[i].Name, Risk_Event__r:this.lsttasklist[i].Risk_Event__r, RiskEventName:this.lsttasklist[i].Risk_Event__r.Name, Phase__c :this.lsttasklist[i].Phase__c, Task__c:this.lsttasklist[i].Task__c, Task_Name__c:this.lsttasklist[i].Task_Name__c, Task_Status__c:this.lsttasklist[i].Task_Status__c, Notes_Log__c:this.lsttasklist[i].Notes_Log__c, Started_Date__c:this.lsttasklist[i].Started_Date__c, Closed_Date__c:this.lsttasklist[i].Closed_Date__c, Risk_Event__c:this.lsttasklist[i].Risk_Event__c, IsExpanded:false, isNotes:false, ButtonLabel:"+"}); } this.tasklist = tempArray; if (tempArray.Notes_Log__c != null) { this.isNotes = true; } } } 

1 Answer 1

1
if (tempArray.Notes_Log__c != null) 

Will never be true. You'll need to check if a record has the value, as in:

this.isNotes = tempArray.some(record => !!record.Notes_Log__c); 
1
  • I've tried this: if (tempArray.Notes_Log__c != null) { this.isNotes = tempArray.some(record => !!record.Notes_Log__c); } and this: this.isNotes = tempArray.some(record => !!record.Notes_Log__c); and this: this.tasklist.isNotes = tempArray.some(record => !!record.Notes_Log__c); None of them work. Can you be more specific? Commented Oct 6, 2023 at 12:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.