且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将文字保留在摘要中

更新时间:2022-03-27 22:26:58

尚不清楚您已经尝试过什么,但是在大多数情况下,不需要Scala xml转换.通常使用Helpers.bind就足够了,并且可以正确处理xml前缀. (在这方面,Scala的xml转换API有时会感觉有些不平衡.)

It’s not clear what you’ve tried already but in most cases there is no need for Scala xml transformations. Using Helpers.bind is usually sufficient and can deal with xml prefixes properly. (Scala’s xml transformations API sometimes feels a bit uneven in this respect.)

不能100%地确定要执行的操作,但这是如果登录后将用户名绑定到<entry:name/>或显示默认文本的方式.

Not 100% sure what you want to do but this is how I’d bind the user name to <entry:name/> if logged in or else show the default text.

class Login {
  def render(xhtml: NodeSeq) = bind("entry", xhtml, "name" -> name _)
  def name(in: NodeSeq) = User.currentUser.map(_.shortName).map(Text(_)) openOr in
}

添加: "name" -> name _部分意味着应使用<entry:name>标记的内容调用方法name,并且结果应替换整个标记. (我必须说,我不太确定您已经知道了关于Lift的知识;我的印象是,如果知道如何绑定User 123的人还应该知道如何绑定其他信息……)

Addition: The "name" -> name _ part means that the method name should be called with the contents of the <entry:name> tag and the result should replace the whole tag. (I must say, I’m not quite sure what you already know about lift; my impression is that if one knows how to bind User 123 one should also know how to bind other information…)

结尾的下划线是帮助此处的编译器所必需的.如果您不想转换标签的原始内容,只需绑定valdef someMethod: NodeSeq,然后在不加下划线或内联的情况下使用它们.例如. bind("entry", xhtml, "name" -> <span>Some NodeSeq</span>)

The trailing underscore is needed to help the compiler here. If you don’t want to do a transformation of the original content of the tag, you’d simply bind a val or a def someMethod: NodeSeq and then use it without underscore or even inline. E.g. bind("entry", xhtml, "name" -> <span>Some NodeSeq</span>)