Skip to main content
Admin User (job) ha fatto una domanda in #Lightning Experience
I'm using a wired function to pull rows from a custom object, but I'm not sure how to edit the response.  This is what I have now:

 

@wire(searchSmartTasks, { smartTaskName: '$smartTaskName', calendarValue: '$calendarValue',})

searchSmartTasks({ error, data }) {

if (data) {

for(let i = 0; i < this.data.length; i++) {

this.data[i].classStatus = 'green';

}

} else if (error) {

this.error = error;

console.log(error);

}

}

My SmarTask object doesn't have a field named classStatus, so I'm trying to append it to the response, so I can access it in my view like this:

 

<ul>

<template for:each={smartTasks} for:item="smartTask">

<li key={smartTask.Id}>

{smartTask.classStatus}

</li>

</template>

</ul>

The above doesn't work.  Any ideas?

From looking over a few sources online it seems the returned data is not editable and the suggestion was to clone the data by doing something like this:

 

// ADDED THIS LINE

@track smartTasks = [];

@wire(searchSmartTasks, { smartTaskName: '$smartTaskName', calendarValue: '$calendarValue',})

searchSmartTasks({ error, data }) {

if (data) {

// ADDED THIS LINE

this.smartTasks = {...data};

for(let i = 0; i < this.smartTasks.length; i++) {

this.smartTasks[i].classStatus = 'green';

}

} else if (error) {

this.error = error;

console.log(error);

}

}

This unfortunately gives me the following error when the searchSmartTasks function is called:

[Assert Violation: Invalid template iteration for value `[object Object]` in [object:vm undefined (46)]. It must be an array-like object and not `null` nor `undefined`.]
3 risposte
  1. 17 mar 2020, 20:20
    Check the return type of the result from apex. I think it is map. If it is not map, then list of records will be in data variable. Also make sure the returned value is not null.

    --

    Magulan Duraipandian

    www.infallibletechie.com
0/9000