拥有一个使用外部 js 库来显示用户通知的 taglib。
由于在许多 View 中调用此标记库,我想知道如何直接从标记中要求库 js 模块,而不是从每个 gsp View 中进行。
目前我在 gsp 文件中使用此代码:
<g:require modules="pnotify"/>
在 taglib 源代码下面:
class MyTagLib {
static namespace = "my"
def myHtmlWithNotifications = { attrs ->
out << "<table>"
// ...
out << "</table>"
}
}
最佳答案
只需以这种方式从 taglib 中调用 require 模块:
class MyTagLib {
static namespace = "my"
def myHtmlWithNotifications = { attrs ->
out << r.require([modules: "pnotify"])
out << "<table>"
// ...
out << "</table>"
}
}
关于grails - 调用 Grails 2 r :require module from a taglib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33461034/