Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery grailsg:formRemote自动检索_Jquery_Grails - Fatal编程技术网

Jquery grailsg:formRemote自动检索

Jquery grailsg:formRemote自动检索,jquery,grails,Jquery,Grails,我的视图区域中存在这个问题,其中我有一个具有onChange属性的标记,用于检索引用到所述标记的所选值的数据。不幸的是,我们将标记包含在中,这样就可以通过的URI检索数据,而无需刷新页面 <!-- The g:formRemote of the view --> <g:formRemote name="formRemote" uri:[controller:'test', action:'functionCall']> <g:select name="sele

我的视图区域中存在这个问题,其中我有一个具有onChange属性的标记,用于检索引用到所述标记的所选值的数据。不幸的是,我们将标记包含在中,这样就可以通过的URI检索数据,而无需刷新页面

<!-- The g:formRemote of the view -->
<g:formRemote name="formRemote" uri:[controller:'test', action:'functionCall']>
   <g:select name="selectedValue" from="${['AA','BB']}"/>
   ${returnData}
</g:formRemote>

//The closure where the formRemote will be calling [TestController.functionCall]
def functionCall(){
   println 'entered'
   def returnData = ''
   if(params.value == 'AA')
      returnData = 'aaa'
   else if(params.value == 'BB')
      returnData = 'bbb'       

   [data:returnData]
}

问题是,我们无法找到一种方法,在更改的值时将模型数据从控制器检索回视图[参考]

您的select标记不必位于formRemote标记内,一个带有remoteFunction调用的常规表单标记就可以实现这一点

发件人:

选择gsp中的标签:

<form>
    <g:select
        optionKey="id" optionValue="name" name="country.name" id="country.name" from="${Country.list()}"
        onchange="${remoteFunction(
            controller:'country', 
            action:'ajaxGetCities', 
            params:'\\'id=\\' + escape(this.value)', 
            onComplete:'updateCity(e)')}"
    ></g:select>
    <g:select name="city" id="city"></g:select>
</form>

我们最近才知道,我们不需要标签就能让理论发挥作用。我们缺少以下格式的onChange=${remoteFunction…}参数:

<g:select 
   name="selectedValue"
   from="${['AA','BB']}" 
   optionKey="<the id of the model with reference to line#9>"
   onChange="${remoteFunction(
     controller:'test', 
     action:'functionCall',
     update:[success:'updateDiv'],
     params:'\'id=\' + escape(this.value)',
     onComplete='displayVal(this)')}"/>
以及包含以下内容的TestController.functionCall:

def functionCall(){
   println 'entered'
   def returnData = ''
   if(params.value == 'AA')
      returnData = 'aaa'
   else if(params.value == 'BB')
      returnData = 'bbb'       

   render(view:'<can be a template or an html page>', model:[data:returnData])
}
<g:select 
   name="selectedValue"
   from="${['AA','BB']}" 
   optionKey="<the id of the model with reference to line#9>"
   onChange="${remoteFunction(
     controller:'test', 
     action:'functionCall',
     update:[success:'updateDiv'],
     params:'\'id=\' + escape(this.value)',
     onComplete='displayVal(this)')}"/>
<div id="updateDiv"></div>
def functionCall(){
   println 'entered'
   def returnData = ''
   if(params.value == 'AA')
      returnData = 'aaa'
   else if(params.value == 'BB')
      returnData = 'bbb'       

   render(view:'<can be a template or an html page>', model:[data:returnData])
}