Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.
Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.
Hey,
I'm looking at a way using Sightly to read data from a node with properties as followed.
Name: footercol1
Type: String[]
Value: {"key1":"value1","key2","value2"},{"key1":"value3","key2","value4"}.
I'm looking a JavaScript way instead of Java to do that.
Using data-sly-list, so far I'm able to print the whole JSON string so far i.e.
Looking forward to some help here.
Thanks.
Gelöst! Gehe zu Lösung.
First: Your JSON is invalid, make sure to fix that first.
I have made an example on how the deal with this in Javascript.
HTL:
<ul data-sly-use.jsonprocessing="json.js" data-sly-list="${jsonprocessing.keys}">
<li>${item}</li>
</ul>
Javascript:json.js
use(function () {
var jsondata = currentPage.properties.get("jsondata");
var jsonlength = currentPage.properties.get("jsondata").length;
var keys = [];
for (var i=0; i < jsonlength; i++) {
keys.push(JSON.parse(jsondata[i]).key1);
}
return {
keys : keys
};
});
Happy programming!
What is your expected output?
Zugriffe
Antworten
Likes gesamt
Why not use Java?
Zugriffe
Antworten
Likes gesamt
First: Your JSON is invalid, make sure to fix that first.
I have made an example on how the deal with this in Javascript.
HTL:
<ul data-sly-use.jsonprocessing="json.js" data-sly-list="${jsonprocessing.keys}">
<li>${item}</li>
</ul>
Javascript:json.js
use(function () {
var jsondata = currentPage.properties.get("jsondata");
var jsonlength = currentPage.properties.get("jsondata").length;
var keys = [];
for (var i=0; i < jsonlength; i++) {
keys.push(JSON.parse(jsondata[i]).key1);
}
return {
keys : keys
};
});
Happy programming!
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten