gpt4 book ai didi

scala - 提升 - 将值列表绑定(bind)到模板

转载 作者:行者123 更新时间:2023-12-01 12:47:39 26 4
gpt4 key购买 nike

这是我的模板 -

      <div class="lift:Admin.showInvitees">
<tr class="success"> <!-- "success" "error" -->
<td><invitee:name></invitee:name></td>
<td><invitee:description></invitee:description></td>
<td><invitee:status></invitee:status></td>
<td></td>
</tr>
</div>

这是片段 -

class Admin {  
def showInvitees(in: NodeSeq): NodeSeq = {
val invitees = Invitation.allInvitations
invitees.flatMap{invitee => bind("invitee", in, "name" -> invitee.name.is, "status" -> invitee.status.is, "description" -> invitee.description.is)}
}
}

我检查了这个question并使用了解决方案。但这对我不起作用。值(value)观根本不受约束。这就是我得到的输出 -

<tr class="success"> 
<td><invitee:name></invitee:name></td>
<td><invitee:description></invitee:description></td>
<td><invitee:status></invitee:status></td>
</tr>

需要帮助将值列表绑定(bind)到模板。

在第一个答案之后我也尝试了这个 -

def showInvitees(in: NodeSeq): NodeSeq = {
val invitees = Invitation.allInvitations
(".invitees" #> invitees.map{ inv =>
".invitee-name" #> inv.name.is &
".invitee-description" #> inv.description.is &
".invitee-status" #> inv.status.is
})(in)

即使这样也行不通-模板 -

<div class="lift:Admin.showInvitees">
<tr class="invitees success"> <!-- "success" "error" -->
<td><span class="invitee-name"></span></td>
<td><span class="invitee-description"></span></td>
<td><span class="invitee-status"></span> </td>
<td></td>
</tr>
</div>

最佳答案

这是绑定(bind)值的旧语法。试试新的:

// snippet
class Admin {
def showInvitees = {
case class Invitee(name: String, descr: String, status: String)
val invitees = List(Invitee("Alex", "for cookies", "ok"), Invitee("Bob", "for beer", "kicked out"))
".invitee" #> invitees.map { i =>
".invitee-name" #> i.name.is &
".invitee-descr" #> i.description.is &
".invitee-status" #> i.status.is
}
}
}

// html
<div class="Admin.showInvitees">
<table>
<tr class="invitee success">
<td><span class="invitee-name"></span></td>
<td><span class="invitee-descr"></span></td>
<td><span class="invitee-status"></span></td>
</tr>
</table>
</div>

// result
<table>
<tbody><tr class="invitee success">
<td>Alex</td>
<td>for cookies</td>
<td>ok</td>
</tr><tr class="invitee success">
<td>Bob</td>
<td>for beer</td>
<td>kicked out</td>
</tr>
</tbody></table>

关于scala - 提升 - 将值列表绑定(bind)到模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14412214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com