FontAwesome与Grails< g:actionSubmit [英] FontAwesome with Grails <g:actionSubmit

查看:153
本文介绍了FontAwesome与Grails< g:actionSubmit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将图标添加到我的保存,删除等按钮中。我有大约五个按钮使用< g:actionSubmit> 标签来调用控制器中的一个动作来执行相应的功能。我的问题是FontAwesome和引导程序的图形符号需要使用< i class =icon - ***> 标签:

 < a href =http://google.com> 
< i class =icon-ok>< / i> Google
< / a>

在grails中,标签之间的这种格式是不可能的(至少在 actionSubmit可以)。 value属性是显示的字符串。有没有解决这个问题的方法?请记住,我仍然需要将按钮操作映射回控制器,这就是为什么我使用直接的<按钮> 标记出现问题的原因,比如bootstrap 。

更新:

我有很多使用当前2个回答。他们都是为了添加图标而工作,但是我遇到了一些麻烦,我不得不破解很多东西来解决问题。我想过另一种解决方案,但在实施时遇到了一些问题。我希望使用taglib的底部作为actionSubmit标记库来编写自己的标记库:

  def actionSubmit = {attrs  - > 
attrs.tagName =actionSubmit
if(!attrs.value){
throwTagError(Tag [$ attrs.tagName]缺少必需属性[value])
}

//添加动作和值
def value = attrs.remove('value')
def action = attrs.action? attrs.remove('action'):value

out<< < input type = \submit \name = \_action _ $ {action} \value = \$ {value} \

// process其余属性
outputAttributes(attrs)

//关闭标记
out<< '/>'
}

我需要做的唯一变化就是给它

 < i class =icon-ok>< / i> 

之间的标记a:

 < g:actionSubmit ...> < /克:actionSubmit可以> 

有人对此有何建议或意见?

 < g:remoteLink class =btn icon-okaction =index> 
点击(不带i标签)

 < g:remoteLink action =index> 
< i class =btn icon-ok>点击(带有i标签)< / i>
< / g:remoteLink>

这两种方法都应该有效。


I've been trying to add icons to my save, delete, etc. buttons. I have about five buttons using the <g:actionSubmit> tag to call an action in a controller to perform the corresponding functions. My problem is that FontAwesome and bootstrap's glyphicons require the <i class="icon-***"> tag to be used like so:

<a href="http://google.com">
    <i class="icon-ok"></i> Google
</a>

In grails this format of the tag in between the initial tag is not possible (at least with actionSubmit). The value attribute is the string that is displayed. Is there any work around for this? Keep in mind I still need to map the buttons action back to a controller which is why I've had issue using a straight <button> tag like what is recommended for bootstrap.

UPDATE:

I'm having a lot of problems using the current 2 answers. They both work for adding the icons, but I'm getting some nuisances that I'm having to hack a lot of things up to fix. I thought about another solution but am having some problems implementing it. I'd like to write my own tag lib using the base of the taglib as the actionSubmit tag lib below:

def actionSubmit = {attrs ->
    attrs.tagName = "actionSubmit"
    if (!attrs.value) {
        throwTagError("Tag [$attrs.tagName] is missing required attribute [value]")
    }

    // add action and value
    def value = attrs.remove('value')
    def action = attrs.action ? attrs.remove('action') : value

    out << "<input type=\"submit\" name=\"_action_${action}\" value=\"${value}\" "

    // process remaining attributes
    outputAttributes(attrs)

    // close tag
    out << '/>'
}

The only change I need to make is to give it the ability to take the

<i class="icon-ok"></i>

tag in between a:

<g:actionSubmit ...> </g:actionSubmit>

Does anyone have suggestions or for this implementation?

解决方案

Try passing the class name to remoteLink, which creates a link that uses Ajax to call a remote function and you can add your fontAwesome classes to it.

<g:remoteLink  class="btn icon-ok" action="index"  >
    click (without i tag)
</g:remoteLink>

or

<g:remoteLink  action="index" >
       <i class="btn icon-ok">click (with i tag) </i>
</g:remoteLink>

Both approaches should work.

这篇关于FontAwesome与Grails&lt; g:actionSubmit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆