1

I am passing a list of objects from my controller to my page , on loading of my page i want to invoke a javascript function on each of the element in the list coming from the controller .. HOW can i achieve that , i know i cannot mix and match javascript and ${}(g-strings) , so i dont have any idea. pls help

code: from controller , the DurationTable contains expiry a date field in itself

def test = {
    [durationTablelist: DurationTable.list()]
}

code on gsp ::

jQuery(document).ready(function() {
    var counter = 0;
    var myarraylist = new Array();
    myarraylist = "${durationTablelist}";
    for(counter=0;counter<"${durationTablelist.size()}";counter++){
        // call some function on each of the element in the list passed from controller
        dont know what to write here..
    }

2 Answers 2

0

there are a bunch of ways you can do it.

  1. You can use scriplets, as seen here.
  2. You could use jquery to invoke an action on your controller which returns json, and then populate the array with the json response.

I personally would do option 2.

0

You need to do something like ;

import grails.converters.JSON

  ...
  render DurationTable.list() as JSON

for more info refer here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.