@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:
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`.]// 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);
}
}
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 Duraipandianwww.infallibletechie.com