Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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..
    }
share|improve this question
add comment (requires an account with 50 reputation)

2 Answers

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.

share|improve this answer
add comment (requires an account with 50 reputation)

You need to do something like ;

import grails.converters.JSON

  ...
  render DurationTable.list() as JSON

for more info refer here

share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.