我相信 Durandal 模态在 Durandal 2.1 中受到了喜爱,尽管我不知道它是否会响应。
与此同时,Durandal 提供了您实现自己的模态功能所需的所有挂钩 - 包括定义不同类型的模态对话框的能力。您可以在此处阅读更多信息:
http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals.html
我通过在 google 群组上找到的一些代码对此进行了简短的试验,并且能够让 bootstrap 3 模态正常工作。
欢迎您尝试一下,看看它是否适合您。请注意,您必须使用 bootstrap 3 才能工作(durandal 2.0 starterkit 等带有 bootstrap 2)
在 dialog.js 中,就在 return dialog; 之前
dialog.addContext('bootstrap', {
addHost: function (theDialog) {
var body = $('body');
$('<div class="modal fade" id="myModal"></div>').appendTo(body);
theDialog.host = $('#myModal').get(0);
},
removeHost: function (theDialog) {
setTimeout(function () {
$('#myModal').modal('hide');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
}, 200);
},
compositionComplete: function (child, parent, context) {
var theDialog = dialog.getDialog(context.model);
$('#myModal').modal('show');
},
attached: null
});
然后激活:
dialog.show(viweModel, null, 'bootstrap')
或者我相信这也可以,但我没有测试它:
dialog.showBootstrap(viewModel)
你的视图应该遵循标记模式:
<div class="messageBox">
<div class="modal-header">
Header Markup
</div>
<div class="modal-body">
Body Markup
</div>
<div class="modal-footer">
Footer Markup
</div>
</div>
这是我获得代码的要点:
https://gist.github.com/webm0nk3y/7603042
以及相关的 google 群组线程:
https://groups.google.com/forum/#!topic/durandaljs/8g7DDCuvlpU