1

I have a JSON response 'result' from JS like below:

[{"Name":"Alexy Portal",
"Description":"New Record <span style="background-color:#FFFF00;">New</span>",
"Title":"New Record <span style="background-color:#FFFF00;">New</span>"}]

I need to put it in table format. I tried to use

<template for:each={result} for:item="res">
   <li key={res.Title}>
      <lightning-formatted-rich-text value={res.Title}></lightning-formatted-rich-text>
   </li>
</template>

to get the Data in HTML so that i can put it in table format. but its not working. Could anyone please suggest any solution? It will be really helpful. Thanks in Advance.

3
  • Welcome to Salesforce Stack Exchange (SFSE)! Thank you for formatting your code - that is helpful. But since it was multiple lines of code, I edited your question in order to format the code as block rather than inline code - just to help see it better. When I did, I discovered what appears to be a stray </div>. Is that a typo or a copy/paste error? If not, that could cause an issue.
    – Moonpie
    Jan 18, 2022 at 13:30
  • it was a typo, made changes Jan 18, 2022 at 13:31
  • Also, please edit your question to elaborate on what you mean by "not working." Are you getting an error? (If so, include exact error text.) Is it giving unexpected results? Or expected results at an unexpected time? Does it seem to just not do anything? Please give more information.
    – Moonpie
    Jan 18, 2022 at 13:33

1 Answer 1

3

For LWC template for:each you MUST specify element with "key" atribute at Top level .
So this code should work.

<template for:each={result} for:item="res">
  <div key={res.Title}>
     <li key={res.Title}>
        <lightning-formatted-rich-text value={res.Title}></lightning-formatted-rich-text>
     </li>
  </div>
</template>

Also please ensure that data in JS saved as Array Not as String or Object

You must log in to answer this question.

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