尝试初始化()Spine's控制器和故障

Trying to init() Spine's Controller and failing

本文关键字:控制器 故障 初始化 Spine      更新时间:2023-09-26

我正在尝试创建一个Spine的控制器并init()它,

jQuery(function($) {
    window.Tests = Spine.Controller.create({
        init: function() {
            console.log('Tests created!');
        }
    });
    window.App = Tests.init();
});

但是我有一个错误

未捕获的类型错误:对象函数result(){返回结果super.constructor.apply(this,arguments);}没有方法"init"

Spine包含在我的控制器文件之前。帮我解决这个问题,为什么Controller.create()(和Controller.sub())返回函数而不是对象?

我试着把它做成一个例子:

jQuery(function($){
  window.App = Spine.Controller.create({
    el: $("body"),
    elements: {
      "#sidebar": "sidebarEl",
      "#contacts": "contactsEl"
    },
    init: function(){
      this.sidebar = Sidebar.init({el: this.sidebarEl});
      this.contact = Contacts.init({el: this.contactsEl});
      Contact.fetch();
    }
  }).init();
});

我通过解决了这个问题

new Tests();