Lift: create an AJAX hyperlink for each element with CSS conversion

I want to create a list of elements and have a hyperlink to each of them that performs some actions, for example. remove the item from the list.

My template looks like this:

<lift:surround with="default" at="content"> <div class="locations lift:Main.locations"> <ul> <li class="one"> <span class="name">Neverland</span> (<a href="#" class="delete">delete this</a>) </li> </ul> </div> </lift:surround> 

I use the following CSS transform to populate it:

 def locations = { ".one *" #> somecollection map { item => ".name" #> item.name & ".delete" #> ???? } } 

Now instead of "????" I would like to add something along the lines of SHtml.a( ()=>delete(item), _) , but _ here is of type CssSel and a argument should be NodeSeq

I could, of course, put a simple xml.Text("delete this") , but I want to reuse the text inside the template.

Or is there another way to generate AJAX hyperlinks?

+6
source share
1 answer

I learned how to do it. Basically, instead of generating the a tag, I should use the tag from the template and put the AJAX code into it through the CSS conversion:

 def locations = { ".one *" # somecollection map { item => ".name" #> item.name & ".delete [onclick]" #> ajaxInvoke (() => delete(item)) } } 

I suspect that in this way it would be possible to create links that work with or without JavaScript

+2
source

Source: https://habr.com/ru/post/899415/


All Articles