1

拥有一个使用外部 js 库来显示用户通知的 taglib。由于在许多视图中调用此标记库,我想知道如何直接从标记中要求库 js 模块,而不是从每个 gsp 视图中进行。

目前我在 gsp 文件中使用此代码:

<g:require modules="pnotify"/>

在 taglib 源代码下面:

class MyTagLib {

    static namespace = "my"

    def myHtmlWithNotifications = { attrs ->
        out << "<table>"
        // ...
        out << "</table>"
    }
}
4

1 回答 1

1

只需以这种方式从 taglib 中调用 require 模块:

class MyTagLib {

    static namespace = "my"

    def myHtmlWithNotifications = { attrs ->
        out << r.require([modules: "pnotify"])
        out << "<table>"
        // ...
        out << "</table>"
    }
}
于 2015-11-01T10:02:49.960 回答