提升片段之间的数据传递

发布于 2024-10-13 16:34:37 字数 231 浏览 1 评论 0原文

我是 scala/lift 的新手,我正在尝试找出解决这个特定问题的最佳方法:

我正在创建一个页面来显示多个“族”的结构。我使用 Lift 的 TreeView 小部件将每个家庭表示为一棵树。我的计划是有一个片段可以生成家庭列表,另一个片段可以呈现单个家庭的 TreeView,并且每个家庭都会调用它。

列表片段生成列表的最佳方式是什么,以便树视图片段可以访问家庭 ID 来为每个家庭构建树?

谢谢。

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 build the tree for each family?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱她像谁 2024-10-20 16:34:37

您应该能够通过嵌套两个片段来做到这一点。在下面的示例中,families 代码段返回将 bindFamily 代码段应用(并连接其结果)到每个系列的结果。

XML:

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

以及相应的Scala代码:

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.
}

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.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文