Skip to main content
Level 3
Mar 28, 2017 8:05 AM UTC
Solved

Displaying values of Multifieldpanel component

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Adobe Employee
Mar 28, 2017 9:23 AM UTC

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
    };
});

10 replies

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
Mar 28, 2017 9:23 AM UTC

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
    };
});

Translate
Level 3
Mar 28, 2017 10:01 AM UTC

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

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Mar 28, 2017 10:45 AM UTC

Is this in a String-array?

Translate
Level 3
Mar 28, 2017 11:17 AM UTC

Feikke please see the attachment.

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Mar 28, 2017 12:01 PM UTC

You need to handle it as an array.

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

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

    return {
        json : json
    };
});

Translate
Level 3
Mar 28, 2017 12:34 PM UTC

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.

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Mar 28, 2017 12:42 PM UTC

Are you using 6.2?

Translate
Level 3
Mar 28, 2017 5:03 PM UTC

Feike Visser wrote...

Are you using 6.2?

 

Yes

Translate
Feike_Visser1
Adobe Employee
Adobe Employee
Mar 29, 2017 1:38 PM UTC

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

Translate
Level 3
Mar 30, 2017 8:13 AM UTC

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.

Translate