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
Solved! Go to Solution.
Views
Replies
Total Likes
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
};
});
Views
Replies
Total Likes
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
};
});
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Is this in a String-array?
Views
Replies
Total Likes
Feikke please see the attachment.
Views
Replies
Total Likes
You need to handle it as an array.
use(function () {
var values = String(properties.get("values"));
var json = JSON.parse("["+values+"]");
return {
json : json
};
});
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
Are you using 6.2?
Views
Replies
Total Likes
Feike Visser wrote...
Are you using 6.2?
Yes
Views
Replies
Total Likes
Can you export the content you have? So I can compare the JSON-Strings
Views
Replies
Total Likes
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.
Views
Replies
Total Likes