twitter-bootstrap - Bootstrap 中的Grails全局函数

标签 twitter-bootstrap grails

我正在使用Grails 2.1.0,并被这2岁的帖子撞了一下:Is there a way to make functions accessible across controllers in Grails?

Burt建议在该处创建一个功能,所有使用Bootstrap的 Controller 都可以使用。我已经尝试过使用它的发现,但是每次我修改 Controller (添加或删除您可能认为的任何内容)时,Grails都会为我提供:

No signature of method: mycontroller.myfunctionfrombootstrap() is applicable for argument types: () values: []



这是Grails 2.1.0的“功能”吗?我想念什么吗?

不能升级Grails。

在 bootstrap 中,我有:
for (controllerClass in grailsApplication.controllerClasses) {
    controllerClass.clazz.metaClass.myfunctionfrombootstrap= {
        return stuff; 
    }
}

最佳答案

在开发模式下修改 Controller 时,Grails会对其进行重新编译,并在新类中插入插槽以替换以前的版本。但是 bootstrap 不会再次运行,因此新类不会将您的额外功能添加到其元类中。

而不是使用元类,您应该考虑将可重用的逻辑放入服务或taglib中。

关于twitter-bootstrap - Bootstrap 中的Grails全局函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28485355/

相关文章:

java - grails:如何禁用<s2ui:form>标记的可调整大小的属性

debugging - 在 IntelliJ Idea 中调试时避免 Groovy/Grails 内部机制

grails - Grails应用程序不会使用grails run-app在浏览器中自动启动

java - Spring Boot 中 Grails 的 BootStrap#init 等效项?

jquery - Bootstrap 输入不再四舍五入

angular - Bootstrap Navbar 无法正常工作 : AngularCLI

css - 使用 SASS mixin 还是创建单独的类更好?

grails - 无法运行Grails ACL插件:创建名称为 'afterAclCollectionRead'的bean时出错

html - 在CSS中将不透明度值设置为多模态

ruby-on-rails - Capistrano 错误:Sprockets::FileNotFound:找不到文件 'bootstrap-sprockets'