How to bind the Map to View in the Snippet ?

3 views
Skip to first unread message

Neil.Lv

unread,
Nov 8, 2009, 10:23:38 PM11/8/09
to Lift
Hi all,

How to bind the Map to View in the Snippet ?

This is the bind code
###
scala.collection.mutable.Map[String,List[String]] =
Map(2009/10/09 -> List(St1), 2009/10/10 -> List(Hello, M7, 123,
da))

var data = Map(2009/10/09 -> List(St1), 2009/10/10 -> List(Hello,
M7, 123, da))
def doList(in : NodeSeq) : NodeSeq = {
data.foreach(d=> {
bind("data", in,
"time" -> Text({d._1}),
"list" -> bindList(d._2)
)
})

def bindList(lists:List[String]) = {
lists flatMap { l =>
bind("sec", chooseTemplate("data", "list", in),
"title" -> Text(l))
}
###

It always show this message:
found : Unit
required: scala.xml.NodeSeq
data.foreach(d=> {


Cheers,
Neil


Naftoli Gugenheim

unread,
Nov 8, 2009, 10:35:10 PM11/8/09
to lif...@googlegroups.com
That should not be foreach but flatMap.
Foreach is like map but returns Unit, and flatMap is like map but it concatenates the resulting elements, which must be iterable (or iterators, depending).

-------------------------------------

Neil.Lv

unread,
Nov 8, 2009, 10:45:44 PM11/8/09
to Lift

How should i write the bind code ?

var data = Map(2009/10/09 -> List(St1), 2009/10/10 -> List(Hello, M7,
123,da))
....

data.flatMap(d=> {
Log.info(" *************************:" + d)
bind("data", in,
"date_title" -> Text("222")
)
})

Get this erors:
found : Iterable[scala.xml.Node]
required: scala.xml.NodeSeq
data.flatMap(d=> {

I'm not familiar with this.

I want the page show like this:
date - 2009/10/09
st1
date - 2009/10/10
Hello
M7
123
da

Cheers,
Neil


On Nov 9, 11:35 am, Naftoli Gugenheim <naftoli...@gmail.com> wrote:
> That should not be foreach but flatMap.
> Foreach is like map but returns Unit, and flatMap is like map but it concatenates the resulting elements, which must be iterable (or iterators, depending).
>
> -------------------------------------
>

David Pollak

unread,
Nov 8, 2009, 11:06:17 PM11/8/09
to lif...@googlegroups.com
On Sun, Nov 8, 2009 at 7:45 PM, Neil.Lv <ani...@gmail.com> wrote:


 How should i write the bind code ?

 var data = Map(2009/10/09 -> List(St1), 2009/10/10 -> List(Hello, M7,
123,da))
 ....

     data.flatMap(d=> {
data.toList.flatMap(...)
 



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

Neil.Lv

unread,
Nov 9, 2009, 12:48:31 AM11/9/09
to Lift
David,

Thanks very much!

It works now and can be shown in the page !

Cheers,
Neil

On Nov 9, 12:06 pm, David Pollak <feeder.of.the.be...@gmail.com>
wrote:
> Beginning Scalahttp://www.apress.com/book/view/1430219890
Reply all
Reply to author
Forward
0 new messages