In my project I am using Marionette with stickit for two way data binding.
In there I need to clone div element which has select and textbox.
var $template = $('#template-clone');
var $clone = $template.clone();
$clone.show();
var observeSelectID = $clone.find('select').attr('id');
var selectID = '#'+observeSelectID;
after that I am trying to bind newly created element using stickit.
this.addBinding(null, {
selectID : {
observe : observeSelectID,
initialize : function($el) {
$(selectID).select2({
});
},
},
selectOptions : {
collection : function(data) {
var option = "{Label value pair JSON String}"
return {
'opt_labels' : ['List'],
'List' : option
};
}
}
});
But any changes in the select box won't trigger model changes.
Got the solution: Add the handler for select2 stickit.
and when new element is created add its bindings
will make select2 bindings.