使用Backbone启动Bootstrap模式已被证明是一个巨大的痛苦。
以下是我的HTML文件中的内容:
<body>
<div id="teamSnapImportDiv"></div>
<script>
function importFromTeamSnap(event) {
event.preventDefault();
alert('agegage');
var aimportTeamSnapView = new importTeamSnapView({el: $("#teamSnapImportDiv")});
var rendered = aimportTeamSnapView.render();
//$(rendered.el).appendTo(this.$el).hide().fadeIn().slideDown();
};
</script>
<script type="text/html" id="teamsnap-import-template">
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button id="cancelTeamSnapImport" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button id="confirmTeamSnapImport" type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</script>
</body>
这是我的Backbone视图:
var importTeamSnapView = Backbone.View.extend({
tagName: "div",
id: 'teamSnapImportDiv',
initialize: function() {
},
render: function (){
var importTeamSnapTemplate = document.getElementById('teamsnap-import-template').innerHTML;
this.$el.html(_.template(importTeamSnapTemplate)());
}
});
我需要做些什么来完成这项工作?我可以得到其他的东西,但模态的东西是行不通的。其他示例并未说明需要完成的工作或原因。
答案 0 :(得分:0)
答案 1 :(得分:-1)
尝试使用this approach。
模态JS
var BaseModalView = Backbone.View.extend({
id: 'base-modal',
className: 'modal fade hide',
template: 'modals/BaseModal',
events: {
'hidden': 'teardown'
},
initialize: function() {
_(this).bindAll();
this.render();
},
show: function() {
this.$el.modal('show');
},
teardown: function() {
this.$el.data('modal', null);
this.remove();
},
render: function() {
this.getTemplate(this.template, this.renderView);
return this;
},
renderView: function(template) {
this.$el.html(template());
this.$el.modal({show:false}); // dont show modal on instantiation
}
});
把手模板
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<a href="#" class="btn">Close</a>
<a href="#" class="btn btn-primary">Save changes</a>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
家长视图
modalView = new BaseModalView();
modalView.show();
// Modal view automatically bound to the body and removes itself on hidden;