我希望创建一个Durandal自定义对话框,在现有的可组合视图模型周围添加带有标题和页脚的窗口框架.
我制作了customModal.html模板
<div class="messageBox">
<div class="modal-header">
<h3 data-bind="text: title"></h3>
</div>
<div class="modal-body">
<!--ko compose: { model: model, template: view }-->
<!--/ko-->
</div>
<div class="modal-footer" data-bind="foreach: options">
<button class="btn" data-bind="click: function () { $parent.selectOption($data); }, text: $data, css: { 'btn-primary': $index() == 0, autofocus: $index() == 0 }"></button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
如您所见,我希望在customModal模板的主体内构建一个viewmodel.这样传入的视图模型不依赖于模态显示,但可以轻松使用.
我已经制作了一个这样的customModal.js模型:
define(['plugins/dialog'], function (dialog) {
var CustomModal = function (title, model, view, options) {
this.title = title;
this.model = model;
this.view = view;
this.options = options;
};
CustomModal.prototype.selectOption = function …Run Code Online (Sandbox Code Playgroud)