为RemoteFunction中的一个参数传递两个值

时间:2014-07-16 13:34:15

标签: ajax grails params

GSP

<g:select from="['AFFILIATES', 'CSE','DISPLAYADS','EMAIL','MOBILEWEB','OTHERS','ORGANIC','SEO', 'SEM']" name="mv" id = "mv" 
           onchange="${remoteFunction(
           controller:'Pgtyp', 
           action:'ajaxGetMv', 
           params:'\'mv=\' + escape(this.value)+\'&date_hour=\'+z+\'&date_hour=\'+ b',
           //params:'\'mv=\'+this.value',
           onSuccess: 'printpgtyp(data)')}"
></g:select> 

控制器

def pgtyp = Pgtyp.executeQuery("select p.date_hour ,p.visits, p.mv, p.browser,p.pagetype,p.platform,p.device,p.time_period from Pgtyp p where p.mv = ? and p.date_hour >= ? and p.date_hour <= ?  order by col_0_0_ asc ",[params.mv, params.date_hour,params.date_hour])

这是我尝试为一个参数传递两个值的方法。我究竟做错了什么?我如何使其发挥作用?

UPDATE1

这是我得到的错误:

ERROR:Expected positional parameter count: 3, actual parameters: [SEO, [[Ljava.lang.String;@6e5980, [Ljava.lang.String;@6e5980]] [select p.date_hour ,p.visits, p.mv, p.browser,p.pagetype,p.platform,p.device,p.time_period from Pgtyp p where p.mv = ? and p.date_hour >= ? and p.date_hour <= ? order by col_0_0_ asc ]. Stacktrace follows:
Message: Expected positional parameter count: 3, actual parameters: [SEO, [[Ljava.lang.String;@6e5980, [Ljava.lang.String;@6e5980]] [select p.date_hour ,p.visits, p.mv, p.browser,p.pagetype,p.platform,p.device,p.time_period from Pgtyp p where p.mv = ? and p.date_hour >= ? and p.date_hour <= ? order by col_0_0_ asc ]
    Line | Method
->>   13 | doCall    in marchmock2.PgtypController$_closure1$$EOkBYvqz
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    200 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread

1 个答案:

答案 0 :(得分:1)

您需要在控制器中使用params.list()方法:

def pgtyp = Pgtyp.executeQuery("select p.date_hour ,p.visits, p.mv, p.browser,p.pagetype,p.platform,p.device,p.time_period from Pgtyp p where p.mv = ? and p.date_hour >= ? and p.date_hour <= ?  order by col_0_0_ asc ", [ params.mv ] + params.list( 'date_hour' ).collect{ dateFormatter.parse( it ) } )