grails - Passing javascript variable to gsp g:link tag - Stack Overflow

I am looking to pass a javascript variable in the id field of a g:link gsp tag but don't know how

I am looking to pass a javascript variable in the id field of a g:link gsp tag but don't know how to do it. If I am going about this the wrong way let me know.

Here is what I have:

  • a table which each row has the id I want to pass in the g:link
  • javascript that onClick of the table row sets a javascript variable with the value of the row id


    <r:script disposition="head">
      var data = -1;
      $(document).ready(function () {
        $('#${tableId} tr').click(function (event) {
          data = $(this).attr('id');
        });
      });
    </r:script>

  • then i want to pass the javascript data variable to a g:link

    <li><g:link controller="filterIntraday" action="show" id="??????">View</g:link></li>

I can't get this to work. How do I set the javascript variable in the gsp tag. Or what is another way to go about passing a client side variable in the g:link tag ?

Thanks.

I am looking to pass a javascript variable in the id field of a g:link gsp tag but don't know how to do it. If I am going about this the wrong way let me know.

Here is what I have:

  • a table which each row has the id I want to pass in the g:link
  • javascript that onClick of the table row sets a javascript variable with the value of the row id


    <r:script disposition="head">
      var data = -1;
      $(document).ready(function () {
        $('#${tableId} tr').click(function (event) {
          data = $(this).attr('id');
        });
      });
    </r:script>

  • then i want to pass the javascript data variable to a g:link

    <li><g:link controller="filterIntraday" action="show" id="??????">View</g:link></li>

I can't get this to work. How do I set the javascript variable in the gsp tag. Or what is another way to go about passing a client side variable in the g:link tag ?

Thanks.

Share Improve this question edited Apr 13, 2013 at 0:34 phil.e.b asked Apr 12, 2013 at 23:38 phil.e.bphil.e.b 2,6212 gold badges17 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

How about changing "href" attribute inside event function:

function (event) {
    data = $(this).attr('id');
    $("link-selector").attr("href", "${createLink(controller: 'filterIntraday', action: 'show')}/" + data);
}

You cannot set the id in the gsp tag because the tag is already processed. What you can do is change the href of the generated html. To do that you need to assign an id to the <a> element.

<li><g:link controller="filterIntraday" action="show" elementId="linkToFilter">View</g:link></li>

This will create something like:

<li>a<a href='yourapp/filterIntraday/show' id="linkToFilter" /></li>

Then in your javascript you can change the href:

data = $(this).attr('id');
$link = $('#linkToFilter');
$link.attr('href', $link.attr('href')+'/'+data);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745452971a4628355.html

相关推荐

  • grails - Passing javascript variable to gsp g:link tag - Stack Overflow

    I am looking to pass a javascript variable in the id field of a g:link gsp tag but don't know how

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信