DOMAIN CLASS
package marchmock2
class Pgtyp {
Date date_hour
String mv
String pagetype
Integer visits
Integer visits_ly
Integer visits_lw
String time_period
String platform
String device
String browser
static mapping = {
table "pgtyp"
version false
date_hour column: "date_hour"
mv column: "mv"
pagetype column: "pagetype"
visits column: "visits"
visits_ly column:"visits_ly"
visits_lw column:"visits_lw"
time_period column:"time_period"
platform column:"platform"
device column:"device"
browser column:"browser"
}
static constraints = {}
}
CONTROLLER
package marchmock2
import grails.converters.*
import groovy.sql.Sql
class PgtypController {
def ajaxGetMv = {
def pgtyp = Pgtyp.executeQuery("select p.visits from Pgtyp p where p.mv = ?",["params.id"])
render pgtyp as JSON
}
def index() {
}
}
GSP
<html>
<head>
<g:javascript src="jquery-1.10.2.min.js"/>
<g:javascript src="prototype.js"/>
</head>
<body>
<form>
<g:select from="['AFFILIATES', 'SEO', 'SEM','DISPLAYADS']" name="mv"
onchange="${remoteFunction(
controller:'Pgtyp',
action:'ajaxGetMv',
params:'\'id=\' + escape(this.value)',
onSuccess: 'printpgtyp(data)')}">
</g:select>
</form>
<script>
function printpgtyp(data) {
console.log(data)
}
</script>
</body>
</html>
我期待将一系列对象打印到控制台。但是,我在控制台中收到以下输出:
[
each: function,
eachSlice: function,
all: function,
any: function,
collect: function …
]
我打印它的方式有什么问题,还是因为我的GSP的价值没有以某种方式发布到控制器上?