So here is my simple popover module. It can be assigned to the kind that popover will call:
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 is how I installed 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')); } });
I want the popover switch function to be called when this.$el.find('.member') clicked. It works great. However, inside the toggle function, I cannot access "this" from the popover object; instead, "this" contains html from its parent. Therefore, I get an error in the switch function:
TypeError: Object [object HTMLAnchorElement] has no method 'show'
Any ideas on how to access the popall popover object inside a toggle callback?
source share