这是我的小部件模块:
app.module("Widget.MyWidget", function(MyWidget, app, Backbone, Marionette, $, _) {
this.on("start", function(el){
var that = this;
});
this.on("click", function(el){
alert("click");
});
this.renderWidget = function (id) {
var that = this;
var el = '#widget_' + id;
widgetModel = new app.Widget.MyWidget.models.meteo();
widgetModel.getWidget(id)
.fetch({ type: "GET" })
.done(function(){
var widgetView = new that.views.widgetView({model:widgetModel, el : el});
widgetView.render();
})
});
};
});
这是木偶视图:
define(['hbs!modules/myWidget'],function (template) {
var meteoView = Marionette.ItemView.extend({
template: template,
events: {
"dblclick" : "open",
"click" : "select",
"contextmenu .icon.doc" : "showMenu",
"click .show_notes" : "toggleNotes",
"click .title .lock" : "editAccessLevel",
"mouseover" : "showTooltip"
},
onShow: function(){
var view = this;
alert("showing");
}
});
return meteoView;
});
一切正常:模型加载并填充数据,视图在屏幕上显示数据。
但是,我无法在视图上设置任何事件:我想在视图中附加一个点击事件:我做错了什么?
问候
答案 0 :(得分:1)
您必须在视图中定义回调:
var meteoView = Marionette.ItemView.extend({
....
open: function() {},
select: function() {},
showMenu: function() {},
toggleNotes: function() {},
editAccessLevel: function() {},
showTooltip: function() {},
....
}