将控制器中的值传递给GSP - 传递给JavaScript函数 [英] Passing values from a controller to a GSP - to a javascript function

查看:103
本文介绍了将控制器中的值传递给GSP - 传递给JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们需要将一些值从 Controller 传递给视图时,我们使用它通过<$ c

When we need to pass some values from Controller to a view we use to send it through model.

In Controller

$ c> render(view:projectView,model:[p:project]);

render(view : "projectView", model:[p:project]);

在GSP中

<html>
   <head>Test</head>
   <body>${p}</body>
</html>

但是我会抓取 $ {p} code>并在JavaScript方法中使用它。我怎么做到这一点?

But I'd to grab the value of ${p} and make use of it in a JavaScript method. How can I do that?

function messageKeyPress(field, event) {
   var theCode = event.keyCode ? event.keyCode : 
                    event.which ? event.which : 
                    event.charCode;
   var message = $('#messageBox').val();
   if (theCode == 13) {
      var Person = ${p}
   }                            
}

Firefox 抱怨存在语法错误,并且没有使用值 $ {p} 。如何解决这个问题?

Firefox complains that there's a syntax error, and doesn't take the value ${p}. How can I solve this ?

推荐答案

您需要附上 $ {p} $ {p}

You need to enclose ${p} in quotes, like "${p}", if it is not a String in JSON format.

这篇关于将控制器中的值传递给GSP - 传递给JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆