3

这是我的模板-

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

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

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

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

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

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>
4

1 回答 1

4

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

// 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>
于 2013-01-19T13:57:56.103 回答