所以这里又是我的简单弹出模块。它可以分配给将触发弹出窗口的视图:
function(app) {
var Popover = app.module();
Popover.Views.Default = Backbone.View.extend({
className: 'popover',
initialize: function() {
this.visible = true;
this.render();
},
setReference: function(elm) {
this.reference = elm;
this.reference.bind('click', this.toggle);
},
beforeRender: function() {
this.content = this.$el.find('.popover');
},
show: function() {
//this.visible = true;
},
hide: function() {
//this.visible = false;
},
toggle: function() {
this.visible ? this.hide() : this.show();
}
});
// Required, return the module for AMD compliance.
return Popover;
});
这就是我设置弹出框的方式:
Main.Views.Start = Backbone.View.extend({
template: "main/start",
serialize: function() {
return { model: this.model };
},
initialize: function() {
this.listenTo(this.model, "change", this.render);
},
beforeRender: function(){
this.popover = new Popover.Views.Default();
this.insertView(this.popover);
},
afterRender: function() {
this.popover.setReference(this.$el.find('.member'));
}
});
我希望在单击时调用 popover 的切换功能this.$el.find('.member')
。这工作正常。但是在切换功能中,我无法从弹出对象访问“this”,而是“this”包含来自其父级的 html。所以我在切换功能中遇到错误:
TypeError: Object [object HTMLAnchorElement] has no method 'show'
任何想法如何访问切换回调中的实际弹出框对象?