backbone中一个view调用另一个view的方法时报is not a constructor的问题

var LayoutView = Backbone.View.extend({
  initialize: function() {
    var self = this;
    $.get('resources/html/layout.html', function(data) {
      self.template = _.template(data);
      self.render();
    });
  },
  render: function() {
    var self = this;
    $(self.el).html(self.template(self.model.toJSON()));
  }
});

My rendering code :

$(document).ready(function() {
    var LayoutView= new LayoutView({
        el:'#wrapper',
        model:{}
    });
});

定义view时如果是var LayoutView= new LayoutView()这么定义的,就会报上面的错误,应该这么定义var layoutView= new LayoutView(),即改成小写的
参考https://stackoverflow.com/questions/38025477/uncaught-typeerror-view-is-not-a-constructor

你可能感兴趣的:(backbone中一个view调用另一个view的方法时报is not a constructor的问题)