Displaying JSON Object or JSON with HTL and Javascript Use

Avatar

Avatar

akatsuki07

Avatar

akatsuki07

akatsuki07

07-11-2019

How can I display JS object properties or iterate over JSON objects using sly-data-list.

Here's my particular JSON

{"make":"Honda","model":"civic"}

Would something like this require a mixed model with local Java class?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

07-11-2019

try below

HTL

<div data-sly-use.head="logic.js">

<ul data-sly-list="${head.list2}">

  <li>${item.make}</li>

</ul>

</div>

logic.js

use(function () {

    return {

        list2:JSON.parse('[{"make":"Honda","model":"civic"} ,{"make":"Honda2","model":"civic2"}]')

    }

});

Answers (2)

Answers (2)

Avatar

Avatar

akatsuki07

Avatar

akatsuki07

akatsuki07

07-11-2019

Thank you, I was reading it as a JSON in crxde property and overlooked that it's actually a string.

Was missing the JSON.parse function

Avatar

Avatar

akatsuki07

Avatar

akatsuki07

akatsuki07

07-11-2019

Yeah this is spam....