我只想在SELECT更改时渲染部分模板。我尝试过onchange和remotFunction,但它不会编译。
在我写的gsp中:
<g:select name="sawMill" from="${prodBuffer}" value="" onchange="${remoteFunction(action: 'availableProducts')}"/>
并在控制器中:
def availableProducts() {
render(template:"AvailableProductData", model:[prodBuffer: getBufferList()])
}
错误:
Class
groovy.lang.MissingMethodException
Message
Request processing failed; nested exception is org.grails.gsp.GroovyPagesException: Error processing GroovyPageView: [views/orders_and_Store/list.gsp:154] Error executing tag <g:form>: Error evaluating expression [remoteFunction(action: 'availableProducts')] on line [24]: No signature of method: D__Grails_projects_torntrading_grails_app_views_orders_and_Store_list_gsp.remoteFunction() is applicable for argument types: (java.util.LinkedHashMap) values: [[action:availableProducts]]
Caused by
No signature of method: D__Grails_projects_torntrading_grails_app_views_orders_and_Store_list_gsp.remoteFunction() is applicable for argument types: (java.util.LinkedHashMap) values: [[action:availableProducts]]
我已经看到了很多不同的解决方案,但它们更复杂,我只想在选择更改时渲染一段gsp而我认为我不需要任何参数。
答案 0 :(得分:1)
您使用的是什么版本的Grails?
在2.4.x中弃用了remoteFunction
您可以使用自己的ajax函数,如:
<head>
<script type="text/javascript">
function availableProducts(){
$.ajax({
url:'${g.createLink( controller:'product', action:'availableProducts' )}',
data: [sawMill],
type: 'get'
}).success( function ( data ) { $( '#divToUpdate' ).html( data ); });
}
</script>
<body>
<g:select name="sawMill" from="${millList}" value="" onchange="availableProducts()"/>
<div id="divToUpdate"></div>
</body>
我假设您的控制器名为productController,如果没有,请在createLink语句中更改。
您必须告诉功能您要使用模板更新屏幕的哪个区域,在这种情况下,我们要更新ID为divToUpdate的div,再次更改为适合您的gsp。
控制器应该正常工作,假设你在与该控制器的其他gsp文件相同的目录中有一个名为_AvailableProductData的模板。