Reputation: 198258
I want to select all <a>
with class my
in liftweb, and set its text to ???
:
val x = <div>
<a><span class="my">xxx</span></a>
<a class="my">yyy</a>
</div>
I tried:
"a .my *" #> "???"
and
"a" #> (".my *" #> "???")
But neither works, because both of them convert the x
to:
<div>
<a><span class="my">???</span></a>
<a class="my">???</a>
</div>
Which are incorrect, they should only convert the second <a>
.
What's the correct code?
Upvotes: 0
Views: 99
Reputation: 194
When I was fighting for another problem, I read this again(https://www.assembla.com/wiki/show/liftweb/binding_via_css_selectors) and I found a solution.
just use
".my" #> ("a *" #> "???")
instead of
"a" #> (".my *" #> "???")
then everything goes well
Upvotes: 0
Reputation: 7848
As far as I know, there is no direct way to do that using Lift 2.5 and earlier. I believe they will be adding support for that more robust type of binding to Lift 3, but since it is not here yet you will need to work around it.
Since you can work directly with the NodeSeq
on the right of the CssSelector
, something like this should allow you to accomplish what you are looking to do:
"a" #> { ns:NodeSeq =>
if((ns \ "@class").text == "my")
("* *" #> "???").apply(ns)
else
ns
}
Upvotes: 2