I'm using a composite view that has $.dialog called on it's $el.
The composite view is then listing items from a collection.
Now i've tried multiple ways to render the collection items: fetching from outside the composite view before and after attaching it to the view, fetching inside the view, preloading the collection from my server script, etc...
all seem to work but the same problem occurs..
as soon as the composite view see's this collection, it calls it's own initialize function again...
I fully understand that the render function will be called on a collection reset or add... but the initialize??? i have absolutely no idea why this is happening.
showCustomFieldSelect: function(e){
log('triggered');
e.preventDefault();
var cl = new AustApp.Collections.CustomField;
var select = new AustApp.Views.AvailableCustomFieldsList({
el: "#available-custom-fields-popup",
collection: cl
});
cl.fetch();
cl.once("reset", function(){
// this bind was
// previously used for creating the view
// or calling render functions directly
// amongst numerous efforts to debug
}, this);
},
MyApp.Views.AvailableCustomFieldsList = function(){
var AvailableCustomFieldsList = Backbone.Marionette.CompositeView.extend({
template: "#available-contact-list-custom-field-list-js",
tag: "div",
itemView: AustApp.Views.AvailableCustomFieldsListItem,
emptyView: AustApp.Views.EmptyAvailableCustomFieldsListItem,
itemViewContainer: "ul",
templateHelpers: viewHelpers,
initialize: function(){
log('init called'); // called twice?????
this.render();
this.$el.dialog({
title: "Available Custom Fields",
width: '600px',
modal: true,
dialogClass: "round",
});
},
/* stuff */
});
return AvailableCustomFieldsList;
}();
Any help appreciated as I'm flummoxed
AvailableCustomFieldsList
views? IsshowCustomFieldSelect
being called twice, perhaps? If you put a breakpoint in theinitialize
function, can you tell from the call stack why it is happening? – Brian Genisio