在我的项目中,我使用 Marionette 和stickit 进行两种数据绑定。
在那里我需要克隆具有选择和文本框的 div 元素。
var $template = $('#template-clone');
var $clone = $template.clone();
$clone.show();
var observeSelectID = $clone.find('select').attr('id');
var selectID = '#'+observeSelectID;
之后我尝试使用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
};
}
}
});
但是选择框中的任何更改都不会触发模型更改。