gpt4 book ai didi

jquery - 使用主干渲染 Bootstrap 模式

转载 作者:行者123 更新时间:2023-12-03 22:24:20 24 4
gpt4 key购买 nike

我认为代码可以更好地解释我的问题: View :

App.Views.ErrorModal = Backbone.View.extend({
template: window.template('errorModal'),

render: function(){
this.$el.html(this.template(this.model.toJSON()));

this.$("#errorApproveModal").modal({
keyboard: true
});

return this;

}

});

实例化时:

 var error = new App.Models.Errors({title: "Exporting Error", content: "Error"});
var errorModal = new App.Views.ErrorModal({model: error});
errorModal.render();

模态已加载,但我只得到一个空 div

感谢您的帮助!罗伊

最佳答案

最好创建一个单独的类来保存所有模态逻辑,然后从主视图中调用它。

尝试使用this approach .

模态JS

var BaseModalView = Backbone.View.extend({

id: 'base-modal',
className: 'modal fade hide',
template: 'modals/BaseModal',

events: {
'hidden': 'teardown'
},

initialize: function() {
_.bindAll(this, 'show', 'teardown', 'render', 'renderView');
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
}
});

Handlebars 模板

<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</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 -->

家长 View //在按钮点击后触发

modalView = new BaseModalView();
modalView.show();

// Modal view automatically bound to the body and removes itself on hidden;

关于jquery - 使用主干渲染 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16085852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com