Displaying JSON Object or JSON with HTL and Javascript Use | Community
Skip to main content
Level 2
Nov 7, 2019 5:06 PM UTC
Solved

Displaying JSON Object or JSON with HTL and Javascript Use

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Nov 7, 2019 11:08 PM UTC

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"}]')

    }

});

Arun Patidar

3 replies

Level 2
Nov 7, 2019 11:10 PM UTC

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

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Nov 7, 2019 11:08 PM UTC

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"}]')

    }

});

Translate
Arun Patidar
Level 2
Nov 7, 2019 5:52 PM UTC

Yeah this is spam....

Translate