access jelly variable inside <script> tag

kjmauriello
Mega Expert

I have a UI Page that retrieves data like this:

<g:evaluate var='jvar_events' object='true'>

  var dt = new Date(2015, 0, 15, 0,0,0,0);

  var gr = new isUtils();

  var events = gr.getArrayOfObjects('74ad1ff3c611227d01d25feac2af603f', dt);

  events;

</g:evaluate>

That executes fine, and jvar_events is an array of objects (I confirmed this with a <j:forEach... loop.

I need to pass jvar_events to a jQuery function inside the <script></script> block.

<script>

      var $j_custom = jQuery.noConflict(true);

      $j_custom(document).ready(function () {

              parm1:test,

              parm2: test,

              parm3: ${jvar_events}

</script>

I've tried ${jvar_events}, '$jvar_events}, neither works.

I've also tried executing this inside the <script> and using events as parm3:

  var dt = new Date(2015, 0, 15, 0,0,0,0);

  var gr = new isUtils();

  var events = gr.getArrayOfObjects('74ad1ff3c611227d01d25feac2af603f', dt);

when I create the same array inside the <script> tags with javascript it works fine, so I must not be accessing the jelly variable properly.

I cannot find any valid Wiki or articles on the subject.

Any assistance would be greatly appreciated.

Kevin

11 REPLIES 11

Kalaiarasan Pus
Giga Sage

Have you tried "${jvar_events}"?   Per me, this should give you the values


sergioap
Kilo Contributor

As Kalaiarasan P said, "${jvar_events}" should work. Try this:



<script>


  var events = "${jvar_events}";


  var $j_custom = jQuery.noConflict(true);


  $j_custom(document).ready(function () {


  parm1: test,


  parm2: test,


  parm3: events


  }


</script>



If this is not working, try to access it with jelly.jvar_events.


  var events = jelly.var_events;




Regards,


kjmauriello
Mega Expert

I tried both suggested solution with no success,


can you try just logging the variable in your script to see if capturing the jelly variable is the problem?


either


console.log('${jvar_events}');




or even just alert it


alert('${jvar_events}');