[英]Passing values from a controller to a GSP - to a javascript function
When we need to pass some values from Controller
to a view
we use to send it through model
. 当我们需要将一些值从
Controller
传递到view
我们可以使用它通过model
发送它。
In Controller 在控制器中
render(view : "projectView", model:[p:project]);
In GSP 在GSP中
<html>
<head>Test</head>
<body>${p}</body>
</html>
But I'd to grab the value of ${p}
and make use of it in a JavaScript method. 但是我要抓住
${p}
的值,并在JavaScript方法中使用它。 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
complains that there's a syntax error, and doesn't take the value ${p}
. Firefox
抱怨存在语法错误,并且没有采用${p}
值。 How can I solve this ? 我该如何解决?
如果${p}
不是JSON格式的String,则需要将${p}
括在引号中,例如"${p}"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.