2013-08-16 68 views
0

remoteLink用于在下面的Grails项目中调用服务器处理程序。我可以在onLoading中放置blockUi方法,以使远程调用更加友好。如果有一个小的遥控链接,我可以为每个遥控链接执行此操作。但是如果有很多遥控链接,重复这一点并不是我的想象。在ajax上拦截ui加载grails

我想使用GSP标签。有没有像remoteLink ajax加载事件的拦截器的方法来做到这一点而不重复?如果有的话,那么通过放置一个标签就可以排除一些remoteLink,比如:except ='true'

非常感谢您的帮助!

<g:remoteLink action="show" 
      id="1" 
      update="success" 
      onLoading="blockUi()" 
      onComplete="hideProgress()">Show Book 1</g:remoteLink> 

回答

1

您可以创建自己的TagLib,默认情况下调用remoteLinkonLoading

class AjaxTagLib { 
    static namespace = "my" //define a namespace to not conflict with g 

    def remoteLink = { attrs -> 
    //default onLoading attribute 
    if(!attrs.onLoading) { 
     attrs.onLoading = "blockUi()" 
    } 
    g.remoteLink(attrs) 
    } 
} 

然后你可以使用的g.remoteLink是instad:

<my:remoteLink action="show" id="1" update="success">Show Book 1</my:remoteLink>