Expand my Community achievements bar.

SOLVED

Displaying values of Multifieldpanel component

Avatar

Level 3

I have created a multifieldpanel component where the values are getting stored in below json format:

with the name  :definitions

{"node1":"hello","node2":"textarea1"}

How can i print the key(node1,node2) and values(hello,textarea1) separately. I am using sightly with JavaScript-use API. 

Thanks

Akshita

1 Accepted Solution

Avatar

Correct answer by
Employee

Here some sample code:

<ul data-sly-use.listValues="listValues.js" data-sly-list="${ listValues.json }">
  <li>${item} ${listValues.json[item]}</li>
</ul>

 

JS:

use(function () {
    var values = String(properties.get("values"));

    var json = JSON.parse(values);

    return {
        json : json
    };
});

View solution in original post

10 Replies

Avatar

Correct answer by
Employee

Here some sample code:

<ul data-sly-use.listValues="listValues.js" data-sly-list="${ listValues.json }">
  <li>${item} ${listValues.json[item]}</li>
</ul>

 

JS:

use(function () {
    var values = String(properties.get("values"));

    var json = JSON.parse(values);

    return {
        json : json
    };
});

Avatar

Level 3

Feike Visser wrote...

Here some sample code:

<ul data-sly-use.listValues="listValues.js" data-sly-list="${ listValues.json }">
  <li>${item} ${listValues.json[item]}</li>
</ul>

 

JS:

use(function () {
    var values = String(properties.get("values"));

    var json = JSON.parse(values);

    return {
        json : json
    };
});

 

Hi Feike,

It worked out for the above data. Thanks :)

However if i have multiple data as below:

{"node1":"hello","node2":"textarea1"} , {"node1":"bye","node2":"textarea2"}

it is throwing Unexpected token: L error.

Thanks 

Akshita

Avatar

Employee

You need to handle it as an array.

use(function () {
    var values = String(properties.get("values"));

    var json = JSON.parse("["+values+"]");

    return {
        json : json
    };
});

Avatar

Level 3

Feike Visser wrote...

You need to handle it as an array.

use(function () {
    var values = String(properties.get("values"));

    var json = JSON.parse("["+values+"]");

    return {
        json : json
    };
});

 

modified js but still the same error.

Avatar

Level 3

Feike Visser wrote...

Are you using 6.2?

 

Yes

Avatar

Employee

Can you export the content you have? So I can compare the JSON-Strings

Avatar

Level 3

Feike Visser wrote...

Can you export the content you have? So I can compare the JSON-Strings

 

Unable to share the zip file here. giving error.