开发者

Lift (Scala) nested snippets (multiple items per day)

开发者 https://www.devze.com 2023-03-24 06:42 出处:网络
Trying to get started with Scala by playing around with the Lift framework and I\'m having trouble creating what I imagined would be typify a common scenario: I have a list of days and for each day a

Trying to get started with Scala by playing around with the Lift framework and I'm having trouble creating what I imagined would be typify a common scenario: I have a list of days and for each day a list of items for that day (nested lists).

My thought was to take this approach:

<div class="lift:DaySnippet">
    <h1 class="day">Name of Day</h1>
    <ul class="day-items">
        <!-- wanted to have a separate snippet but haven't made it work -->
        <!-- <li class="lift:DayItemSnippet">Item content</li> -->
        <li class="item">
            <span class="name">Name</span>
            <span class=开发者_Go百科"desc">Description</span>
        </li>
    </ul>
</div>

Originally I wasn't going to have the inner snippet but thought that made sense.

So I can define a snippet like this:

class DaySnippet {
    // Ignoring that this is a stupid way to define the data
    val days = ("Monday", ("Item 1", "Item 1 Description") :: Nil) ::
        ("Tuesday", ("Item 2", "Item 2 Description") ::
            ("Item 3", "Item 3 Description") :: Nil) :: Nil;

    def render = {
        // EDIT: Original code was broken, this is what I was trying to show

        "* *" #> days.map { case (day, items) => ".day *" #> day }
    }
}

At any rate, I'm looking for some documents or examples of either nesting snippets and/or how to iterate over nested collections and use CssSels to modify the whole NodeSeq as we go.

I'd be happy to add any additional information that might clarify.


I came up with some code to do what I wanted, but I'm not sure it's optimal so suggestions are welcome:

class DaySnippet {
    // Ignoring that this is a stupid way to define the data
    val days = ("Monday", ("Item 1", "Item 1 Description") :: Nil) ::
        ("Tuesday", ("Item 2", "Item 2 Description") ::
            ("Item 3", "Item 3 Description") :: Nil) :: Nil;

    def render = {
        "* *" #> days.map { case (day, items) =>
            ".day *" #> day & ".item *" #> item.map {
                case (name, desc) =>
                    ".name *" #> name * ".desc *" #> desc
            }
        }
    }
}


Here good discussion, using S.attr to get index of nested snippet is described.

0

精彩评论

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