Displaying values of Multifieldpanel component | Community
Skip to main content
Level 3
March 28, 2017
Solved

Displaying values of Multifieldpanel component

  • March 28, 2017
  • 10 replies
  • 2253 views

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.
Best answer by Feike_Visser1

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
March 28, 2017

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

Level 3
March 28, 2017

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

Feike_Visser1
Adobe Employee
Adobe Employee
March 28, 2017

Is this in a String-array?

Level 3
March 28, 2017

Feikke please see the attachment.

Feike_Visser1
Adobe Employee
Adobe Employee
March 28, 2017

You need to handle it as an array.

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

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

    return {
        json : json
    };
});

Level 3
March 28, 2017

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.

Feike_Visser1
Adobe Employee
Adobe Employee
March 28, 2017

Are you using 6.2?

Level 3
March 28, 2017

Feike Visser wrote...

Are you using 6.2?

 

Yes

Feike_Visser1
Adobe Employee
Adobe Employee
March 29, 2017

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

Level 3
March 30, 2017

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.