resthub/resthub-backbone-stack — pull request #37 by loicfrering (2012-08-30 00:38:16+00:00)
Title: Default rendering strategy with root element, template and context management

# Description

Implement a default rendering strategy with root element, template and context management.

# Documentation

TODO

# Tests

TODO

# Examples

## Example 1

A simple example with (volontarily) no view for each item:

```javascript
var TodosView = Backbone.View.extend({

root: '#todos',
template: todosTemplate,

initialize: function() {
this.collection.on('add', this.add.bind(this));
}
});
```

```html

My TodoList

{{#each this}}

{{title}}

{{/each}}

```

## Example 2

A more elaborated one with a view for each item in the collection:

```javascript
var TodosView = Backbone.View.extend({

root: '#todos',
template: todosTemplate,

initialize: function() {
this.collection.on('add', this.add.bind(this));
},

render: function() {
TodosView.__super__.render.apply(this);
this.collection.each(function(todo) {
this.add(todo);
}, this);
},

add: function(todo) {
var todoView = new TodoView({
model: todo
});
todoView.render();
}
});
```

views/todo.js:
```javascript
var TodoView = Backbone.View.extend({

root: '#todo-list',
strategy: 'append',
template: todoTemplate,
tagName: 'li'

});
```

templates/todos.hbs:

```html

My TodoList

```

templates/todo.hbs:

```html
{{title}}
```