peerigon / alamid

Framework for RESTful JavaScript web applications that run both on the server- and clientside.
http://www.alamidjs.com
MIT License
23 stars 3 forks source link

Creating simple view collections should be easier #179

Open jhnns opened 11 years ago

jhnns commented 11 years ago

Currently you have to write a lot of code to display a collection of models. You have to create a ViewCollection with template and then bind a ModelCollection to the ViewCollection.

This should be easier with less to code. alamid could provide a special foreach data-binder that is used like this:

<div>
    <h1>Users</h1>
    <ul data-bind="foreach: users">
        <li>
            <h2 data-bind="text: name"></h2>
            User since: <span data-bind="text: since"></span>
        </li>
    </ul>
</div>

alamid detects the foreach-binder, creates a ViewCollection with the ul-tag as root-node and everything below as template for each view. Finally the users-collection is bound to the created ViewCollection.

We have to be careful here, because everything below the foreach-tag should not be part of the current view, but the created child views. Therefore these tags should not show up under nodes (former nodeMap)

I still think, that there are many cases where you should rather create a separated list view instead of embedding them like here. But there are also simple cases where this functionality is more elegant.