-
Notifications
You must be signed in to change notification settings - Fork 3
14: CalendarItemViewを作成
Kazuhito Hokamura edited this page Oct 23, 2013
·
1 revision
予定のリストアイテムひとつひとつもViewクラスにしておきます。CalendarItemView
を以下のように定義します。
//...
App.CalendarItemView = Backbone.View.extend({
tagName: 'li',
template:
'<time><%= date %></time>' +
'<span><%= title %></span>',
initialize: function() {
this.render();
},
render: function() {
var html = _.template(this.template, {
date: this.model.dateFormat('HH:mm'),
title: this.model.get('title')
});
this.$el.html(html);
}
});
- CalendarCellViewのreder部分を書き換える
CalendarCellView
のrender
で予定のリストアイテムをつくっている部分をCalendarItemView
を使った記述に書き換えます。
App.CalendarCellView = Backbone.View.extend({
//...
render: function() {
//...
_.each(schedules, function(model) {
var item = new App.CalendarItemView({ model: model });
$list.append(item.el);
}, this);
}
});