打字稿骨干查看事件不火 [英] Typescript Backbone View Events do not fire
问题描述
我试图做一个简单的观点与骨干网进行测试。我已经开始与事件,但没有一个人闪光。为什么呢?
我已经做骨干已经其他像路由等没有问题。谢谢你的时间。
我的骨干定义从 - >此源< -
I'm trying to make a simple view to test with backbone. I've started with events, but no one fires. Why ? I've made already other things with backbone like routing etc. without problems. Thanks for your time. My backbone definitions are from -> this source <-
module Views {
export class MenuView extends Backbone.View {
constructor(viewOptions?: Backbone.ViewOptions) {
super(viewOptions);
}
el = document.body;
events = {
"click #Btn-Start": "navigate",
"click #Btn-Software": "navigate",
"click #Btn-Anderes": "navigate",
"click #Btn-Impressum": "navigate"
};
initialize() {
console.log("initialize"); // fire
}
render() {
console.log("render"); // not fire
}
navigate() {
console.log("navigate"); // not fire
}
}
}
<body>
<div id="Menu">
<div id="Btn-Start"></div>
<div id="Btn-Software"></div>
<div id="Btn-Anderes"></div>
<div id="Btn-Impressum"></div>
</div>
<body>
编辑:尝试使用路由的路由(名称:字符串,回调:功能)和对象的路由。
这似乎与函数引用工作,但不是作为字符串中的路线对象。也许有宣布它在这样的视图的方法。
Tried routes with the route(name: string, callback: function) and the routes as object. It seems to work with a function reference but not as string in the routes object. Maybe there is a way to declare it in the view like these.
推荐答案
使用的setElement功能的构造函数,而不是EL对象内。
Use the setElement function inside the ctor instead of el object.
这篇关于打字稿骨干查看事件不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!