如何使用类型脚本创建 marionete 模块。我看到这个 how to write marionettejs module using typescript?但它对我的情况没有用。我像这样创建了模块
class TestModule extends Marionette.Module {
constructor(options) {
if (!options)
options = {};
var marionetteApp = new MarionetteApp();
marionetteApp.module("myModule", {
startWithParent: false
});
super("myModule", marionetteApp);
}
}
但是它显示错误 http://localhost/Scripts/backbone.marionette.js 中第 3561 列第 5 列未处理的异常
0x800a138f - JavaScript 运行时错误:无法获取未定义或空引用的属性“初始化”
我做错了什么。我是 Marionette 和 typescript 的新手。使用 typescript 创建 Marionette 模块的正确程序是什么 我的申请代码是
class MarionetteApp extends Marionette.Application {
headerRegion: Marionette.Region;
leftRegion: Marionette.Region;
centerRegion: Marionette.Region;
constructor() {
super();
this.on("start", this.initializeAfter);
this.addRegions({ headerRegion:"#headerContainer",leftRegion:"#leftContainer",centerRegion:"#centerContainer"});
}
initializeAfter() {
//alert("started")
this.headerRegion.show(new HeaderView());
this.leftRegion.show(new leftView());
this.centerRegion.show(new CenterView());
var MyModule = new TestModule("Test");
//MyModule.start();
}
}
最佳答案
我使用以下代码解决了这个问题。类中的包装模块。它按预期工作。如果我错了,请纠正我,有人知道正确的程序
class TestModule {
mod: any;
constructor() {
var marionetteApp = new MarionetteApp();
this.mod = marionetteApp.module("myModule", {
startWithParent: false,
initialize: function(){
console.log("initialized");
},
define: function () {
console.log("defined");
}
});
this.mod.on("start", this.onStart);
}
start() {
this.mod.start();
}
onStart() {
console.log("Module started")
}
}
初始化代码
var MyModule = new TestModule();
MyModule.start();
关于backbone.js - 使用 typescript 的 Marionette 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30092245/