根据v2.4.1
Marionette documentation控制器被弃用:
Warning: deprecated. The Controller object is deprecated. Instead of using the Controller
class with the AppRouter,you should specify your callbacks on a plain Javascript object.
我很困惑现在他们被弃用的最佳做法是什么?这是否意味着AppRouter也被弃用了?如果是这样,目前用于开发大规模Marionette应用的模式是什么?
解决方法
您可以使用
Marionette.Object.它与Controller基本相同.
要在AppRouter中使用普通的JavaScript对象,您可以执行以下操作:
var MyController = Marionette.Object.extend({/*...*/}); var AnotherController = Marionette.Object.extend({/*...*/}); var myController = new MyController(); var anotherController = new AnotherController(); var plainJsObject = { doStuff: myController.doStuff,doSomethingDifferent: anotherController.doSomethingDifferent }; var router = Marionette.AppRouter.extend({ controller: plainJsObject });