Jelly Evaluate Tag for Array of Objects

markkeats
Kilo Explorer

I have the following code:

<g:evaluate>

  var someData = [

  {"PropA":"Value1", "PropB":"Value2"},

  {"PropA":"Value3", "PropB":"Value4"}

  ];

</g:evaluate>

<j:forEach items="${someData}" var="jvar_data">

  ${jvar_data.PropA} ${jvar_data.PropB}

</j:forEach>

The evaluate actually builds the data from other sources, but the result is the same - an array of objects that I wish to display in the page.

Unfortunately the UI Page renders nothing, and if I look in the logs I see the following:

WARNING *** WARNING *** ScopedRhinoObjectWrapper: not a wrappable type: org.mozilla.javascript.NativeObject

Any ideas what's going wrong here?

1 ACCEPTED SOLUTION

ghsrikanth
Tera Guru

Please try this - have tested in my local and its working (add <br/> for clarity of output)


Screen Shot 2016-03-30 at 8.27.18 PM.png


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">



<g:evaluate var="jvar_json" jelly="true" object="true">


  var someData = [  


  {"PropA":"Value1", "PropB":"Value2"},  


  {"PropA":"Value3", "PropB":"Value4"}  


  ];  


  someData;


</g:evaluate>  


 


<j:forEach items="${jvar_json}" var="jvar_data">  


      <g:evaluate var="jvar_propA" jelly="true" expression="var propA = jelly.jvar_data.PropA; propA;"/>


      <g:evaluate var="jvar_propB" jelly="true" expression="var propB = jelly.jvar_data.PropB; propB;"/>


      ${jvar_propA} ${jvar_propB}  


  <br/>


</j:forEach>



</j:jelly>



Hopefully it helps


View solution in original post

7 REPLIES 7

Inactive_Us1474
Giga Guru

Hi Mark,



This is JSON notation.


Try using this below code:



<g:evaluate>


  var someData = [  


  {"PropA":"Value1", "PropB":"Value2"},  


  {"PropA":"Value3", "PropB":"Value4"}  


  ];  


</g:evaluate>  


<j:forEach items="${someData}">  


  ${someData[0].PropA} ${someData[0].PropB}


</j:forEach>



Thanks and let me know if any concerns.



Hit Like/Helpful, feedback is appreciated.


ghsrikanth
Tera Guru

Please try this - have tested in my local and its working (add <br/> for clarity of output)


Screen Shot 2016-03-30 at 8.27.18 PM.png


<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">



<g:evaluate var="jvar_json" jelly="true" object="true">


  var someData = [  


  {"PropA":"Value1", "PropB":"Value2"},  


  {"PropA":"Value3", "PropB":"Value4"}  


  ];  


  someData;


</g:evaluate>  


 


<j:forEach items="${jvar_json}" var="jvar_data">  


      <g:evaluate var="jvar_propA" jelly="true" expression="var propA = jelly.jvar_data.PropA; propA;"/>


      <g:evaluate var="jvar_propB" jelly="true" expression="var propB = jelly.jvar_data.PropB; propB;"/>


      ${jvar_propA} ${jvar_propB}  


  <br/>


</j:forEach>



</j:jelly>



Hopefully it helps


Thanks. That's fixed it. It's the nested evaluate tags that seem to be needed within the forEach tag.


geraldcheng
Kilo Contributor

Hi there,



I've tried Srikanth Gunuru's solution and it works fine in a Global application. However when I tried it in a scoped application, it's returning null. Has anyone tried it in a scoped application?



Thanks