March 15, 2020
Estimated Post Reading Time ~

AEM JavaScript Use-API Part 3

AEM JavaScript Use-API String Multi JSON
JSON content parsing, e.g., jcr:content Type string[] with JSON values.

JCR Properties - String[] Multi JSON values

Use-API JavaScript

myProp.js
"use strict";
use(function() {
  let val = [];
  try {
     let myPropStrings = properties.get('myProp') || [];
     val = myPropStrings.map(function(data){
         return JSON.parse(data);
     });
  } catch (e) {
      log.error('Could not read myProp: ' + e.message);
  }
  return val;
});

HTL Sample

<div data-sly-use.data="myProp.js">
  <sly data-sly-list="${data}">
    <h3 data-label="${item.label}">
      ${item.title}
    </h3>
    <div>${item.desc}</div>
  </sly>
</div>




By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.