【问题标题】:grails 3 taglib, html builder and createLInkgrails 3 taglib、html builder 和 createLInk
【发布时间】:2017-04-27 15:42:03
【问题描述】:

是否可以在 grails 3 中使用 createLink 和 HTMLBuilder 创建标签库。我试过了:

def buttonTaglib = { attrs, body ->
        def mb = new groovy.xml.MarkupBuilder(out)
        mb.button(type: "button", class: "btn btn-success") {
            g.createLink(controller: 'test', action: 'show', id: 1) { mkp.yield "buttonTaglib" }
        }
    }

def buttonTaglib2 = { attrs, body ->
        def mb = new groovy.xml.MarkupBuilder(out)
        out << g.createLink(controller:"test", action:"show") << mb.button(type: "button", class: "btn btn-success") { "buttonSimple" }
    }

没有成功。

【问题讨论】:

    标签: grails taglib


    【解决方案1】:

    您的标准输出是否足够,如果是这样,那么简单:

    def buttonTaglib2 = { attrs, body ->
            out << """
    <a href="${g.createLink(controller:"test", action:"show")}" class="btn btn-success">Test</a>
    """
        }
    

    您也可以只渲染模板并将参数或属性传递给模板。然后像通常从控制器到视图一样处理您的值。

    【讨论】:

      【解决方案2】:

      这个对我有用:

      def button = { attrs, body ->
              def mb = new groovy.xml.MarkupBuilder(out)
              out << link(controller: attrs.controller, action: attrs.action, id: attrs.id, params: attrs.params ) {
                  mb.button(type: attrs.type, class: attrs.class) {
                      mkp.yield attrs.name
                  }
              }
      }
      

      【讨论】:

        猜你喜欢
        • 2017-12-12
        • 2012-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-29
        相关资源
        最近更新 更多