Currently I have Control where I create some elements and add them to the DOM via the Control's init() method. They are not contained within the Control's element, so I don't believe normal scoped event handlers will work.
- init: function() {
- this.options.newButton = $("<button>Click Me</button>");
- //append the new button to the dom after the control's element
- this.element.after(this.options.newButton);
- //call on to rebind events given this new option
- this.on();
- }
- "{newButton} click": function() {
- //do something
- }
Notice how I have to call on() to rebind the events based on the newButton object I added to this.options. Otherwise the templated click handler won't do anything.
Not a huge deal, but I am wondering if there is a better/preferred way for me to do this. Also are there any obvious issues with the approach I am currently taking?
Thank you,
Keith