, , , , . , ( <ol>), - <li> s.
, , , <ol class="topic-collection-will-append-to-this"> .
, 100% , :)
window.TopicView = Backbone.View.extend({
template: _.template($("#topic-template").html()),
tag: 'li',
className: 'topic',
initialize: function() {
_.bindAll(this, 'render');
},
render: function() {
$(this.el).html(this.template({topic: this.model}));
return this;
}
});
window.DiscussionView = Backbone.View.extend({
tagName: 'section',
className: 'discussion',
template: _.template($('#discussion-template').html()),
initialize: function() {
_.bindAll(this, 'render');
this.collection.bind('reset', this.render);
},
render: function() {
var $topics,
collection = this.collection;
$(this.el).html(this.template({}));
$topics = this.$(".topics");
this.collection.each(function(topic) {
var view = new TopicView({
model: topic
});
$topics.append(view.render().el);
});
return this;
}
});
<script id="topic-template" type="text/html">
<article id="{{ topic.htmlId() }}">
<a class="section-arrow mir" href="#">toggle</a>
<h3>{{ topic.get('text') }}</h3>
<ol class="topic-collection-will-append-to-this">
</ol>
</article>
</script>
<script type="text/template" id="discussion-template">
...
<ol class="topics">
</ol>
</script>