开发者

value % is not a member of scala.xml.NodeSeq

开发者 https://www.devze.com 2023-02-11 11:57 出处:网络
I\'m trying to work through some Lift examples using CSS Selector Transforms.I\'m attempting this sort of transformation:

I'm trying to work through some Lift examples using CSS Selector Transforms. I'm attempting this sort of transformation:

  • NodeSeq => NodeSeq — a function that transforms the node (yes, it can be a CssBindFunc): "#name" #> ((n: NodeSeq) => n % ("class" -> "dog")) // <span i开发者_高级运维d="name"/> -> <span id="name" class="dog"/>

It's the % that's giving me trouble right now. When I try to write code like this, I get the error value % is not a member of scala.xml.NodeSeq. Is there an import or something that I'm missing?

Here's my snippet:

import scala.xml._
import net.liftweb.util.Helpers._

import model.User

class Users {
  def show = {
    ".userName" #> "name replaced" &
    ".userEmail" #> "email replaced" &
    ".changePassword" #> ((n: NodeSeq) => n % ("href" -> "changePassword"))
  }
}


Only Elem contains the % method. NodeSeq is not an Elem, but a collection of Nodes, which may or may not be Elems. And I'm not sure if Lift's helpers include implicits to create MetaData, but if not, you'd need something like

myNodeSeq map {
  case e: Elem => e % new UnprefixedAttribute("href","changePassword",xml.Null)
  case x => x
}

to cover the generic case.


Here is the way to do what you want. It's pretty much equivalent but it doesn't throw any error.

import scala.xml._
import net.liftweb.util.Helpers._
scala> val res1 = "#name" #> ((n:NodeSeq) => ("* [class]" #> "dog")(n))
res1: net.liftweb.util.CssSel = CssBind(Full(#name), Full(IdSelector(name,Empty)))
scala> res1(<span id="name"/>)
res2: scala.xml.NodeSeq = NodeSeq(<span id="name" class="dog"></span>)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号