0

我现在很坚持。我收到以下错误:

TypeError: listenTo is undefined    
return listenTo.call(this, evtSource, events, _.bind(callback, context));

我不明白为什么会发生此错误。我真的不知道listenTo 期望什么。当我更改Backbone.Marionette.CompositeViewBackboneView工作正常时。有任何想法吗?

请参见下面的代码:

define([
        "jquery",
        "backbone",
        "marionette",
        ],
function($, Backbone, Marionette){

    var CompositeView = Backbone.Marionette.CompositeView.extend({
      // The DOM Element associated with this view
      el: ".example",
      // View constructor
      initialize: function() {
          // Calls the view's render method
          this.render();
      },
      // View Event Handlers
      events: {

      },

      // Renders the view's template to the UI
      render: function() {
          // Setting the view's template property using the Underscore template method
          //this.template = _.template('ddd', {});
          // Dynamically updates the UI with the view's template
          this.$el.html('123123123123123123123123');
          // Maintains chainability
          return this;
      }

    });

    // Returns the View class
    return CompositeView;
  }
);
4

2 回答 2

2

listenToBackbone.Events的一个特性。Backbone.View 和随后的 Marionette.View 包括 Backbone.Events 功能。您正在调用它,就好像它是全局定义的;因此,你得到listenTo is undefined.

你可以用类似的东西来调用它myView.listenTo(model, 'change', myView.doSomething); 或者如果当前上下文是您想要进行监听的视图实例,this.listenTo(object, 'eventName', this.doSomething).

于 2013-01-26T06:08:39.300 回答
2

将主干更新到 v0.9.9 或更高版本。

https://github.com/marionettejs/backbone.marionette/blob/master/upgradeGuide.md

https://github.com/marionettejs/backbone.marionette/blob/master/changelog.md

于 2013-01-26T20:54:35.873 回答