Marionette 2.4.1 无法创建CollectionView实例

Marionette 2.4.1 Can't Create CollectionView Instance

我在 Marionette 2.4.1 中创建 CollectionView 实例时遇到问题。这是一个非常简单的例子。不确定发生了什么。似乎是 Marionette 错误。

var AppointmentModel = Backbone.Model.extend({
});

var AppointmentCollection = Backbone.Collection.extend({
  model: AppointmentModel
});

var TimeSlotView = Marionette.ItemView.extend({
});

var AppointmentCollectionView = Marionette.CollectionView.extend({
  childView: TimeSlotView
});

这是模板:

<script id="time-slot-template" type="text/template">
  <div class="col-xs-4">
    <button class="btn-time-slot" data-appointment-time="<%= date %>">
      <%= date %>
    </button>
  </div>
</script>

主要代码:

//...inside ajax success

// result looks like this:
// [ "2015-1-2", "2015-1-17", "2015-2-1", "2015-2-8" ]

var appointmentCollection = new AppointmentCollection(result.map(function(apt){
  return new AppointmentModel({ date: apt });
})); //browser console shows a good valid collection

var appointmentCollectionView = new AppointmentCollectionView({ collection: appointmentCollection });
// Undefined is not a function

我做错了什么?

您发布的代码看起来没有任何问题。

可以确认它对我有用...http://jsfiddle.net/nuewwdmr/

我所做的唯一更改是在模型中包含 idAttribute,但这不会影响您遇到的这个问题。

var AppointmentModel = Backbone.Model.extend({
    idAttribute: 'date'
});

我唯一能想到的是 Marionette 依赖于 Babysitter 和 Wreqr(还有下划线,显然是 Backbone)。您是否包括了这些依赖项?