I\'d just like to understand the decisions behind Backbone.Marionette\'s view regarding UI elements. When instantiating a Marionette.View on an existing DOM element, like this:<
Attaching a view to an existing element is the exception. The normal view lifecycle involves calling render
, and without doing that there would be nothing for the UI elements to bind to.
Just call this.bindUIElements()
in your initialize
method when you need to attach a view to an existing element.
I think you have that problem because you have to access to the jQuery element with
this.ui.whatever
Because "this" is already a view instance. See: http://marionettejs.com/docs/v2.4.4/marionette.itemview.html#organizing-ui-elements
When I am working with Marionette, I put the code that has to access the ui elements inside the onShow method. This event is fired after the dom is ready and the elements are ready to be manipulated. Inside this method, your ui.whatever will now be pointing to an element and not a string.