覆盖 Lift ajaxRadio toForm 默认标记
我的表单中有 ajaxRadio,但 Lift 为我生成了不需要的标记(它用 span 包装输入标记,我想标记 tag)。 可以覆盖默认的 toForm 函数或完全覆盖 htmlize 方法,该方法称为
object ChoiceHolder {
var htmlize: ChoiceItem[_] => NodeSeq = c => (<span>{c.xhtml} {c.key.toString}<br/> </span>)
}
那么如何获取输入标签周围的标签而不是跨度?
多谢。
I have ajaxRadio in my form, but Lift generates undesirable markup for me (it wraps input tag with span, and I would like to label tag).
It is possible to override default toForm function or exactly override method htmlize, which is called
object ChoiceHolder {
var htmlize: ChoiceItem[_] => NodeSeq = c => (<span>{c.xhtml} {c.key.toString}<br/> </span>)
}
So how to get, that around input tags will be labels and not spans?
thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑到
ChoiceItem
类似于,并且您按如下方式调用
toForm
方法,您可以使用
它可能返回类似
or 的内容,如果您想将标签包裹起来
,它可以为您提供
有点复杂:
evalElemWithId
(importnet.liftweb.util.Helpers.evalElemWithId
) 获取NodeSeq
的第一个元素(例如 choiceItem.xhtml ),并向其添加一个id
属性。之后,将调用接收此 id 的匿名函数,以便您可以在标签的for
属性中使用它。编辑
请注意,
ChoiceHolder.htmlize
是一种全局函数,将通过所有ChoiceHolder.toForm
调用进行调用。因此,只有当您想在所有地方都具有相同的布局时,全局更改它才有意义。如果您只想在一种情况下拥有不同的布局,那么最好只调用一些
choiceToForm
方法。Considering that the
ChoiceItem
is something likeand you call the
toForm
method as followsyou could use
which might return something like
or, if you want to wrap the label around
which gives you
A bit complicated:
evalElemWithId
(importnet.liftweb.util.Helpers.evalElemWithId
) takes the first element of aNodeSeq
(e.g. choiceItem.xhtml), and adds anid
attribute to it. Afterwards the anonymous function will be called which receives this id so that you can use it in thefor
attribute of the label.Edit
Note that
ChoiceHolder.htmlize
is kind of a global function which will be called through allChoiceHolder.toForm
calls. So it only makes sense to globally change it if you want to have the same layout everywhere.If you just want to have a distinct layout in one case, you’re probably better off just calling some
choiceToForm
method.所以最后我自己找到了解决方案。
它不是我想象的那么干净,但它有效!
因此,对于具有相同问题的下一代 - 我用我自己的函数包装 ajaxRadio:
并且该函数如下所示:
So finally I found solution by myself.
It's not so clean I would expected, but it works!
So for future generation with same problem - I wrap ajaxRadio with my own function:
and this function looks like: