开发者

Lift passing data between snippets

I am new to scala/lift and I am trying to figure out the best way to solve this particular problem:

I am creating a page to display the structure of multiple "families". I am representing each family as a tree using Lift's TreeView widget. My plan was to have one snippet that would generate the list of families, and another snippet that would render the TreeView of a single family, and it would get called for each family.

What is the best way for the list snippet to generate the list so that the treeview snippet can have access to the family id to buil开发者_开发问答d the tree for each family?

Thanks.


You should be able to do this by nesting your two snippets. In the example below, the families snippet returns the result of applying (and concatenating the result of) the bindFamily snippet to each of the families.

The XML:

<lift:FamilyTree.families>
    <!-- start per-family ui -->
    <family:tree/>
    <!-- end per-family ui -->
</lift:FamilyTree.families>

And the corresponding Scala code:

def families(xhtml: NodeSeq): NodeSeq = {
  val families = ...
  families.flatMap(f => bindFamily(f, xhtml))
}

def bindFamily(f: Family, xhtml: NodeSeq): NodeSeq = {
  bind("family", xhtml,
       "tree" -> bindFamilyTree(f, xhtml))
}

def bindFamilyTree(f: Family, xhtml: NodeSeq): NodeSeq = {
  // return your tree view here.
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜