Durandal 2.0 custom dialog

前端 未结 1 2006
名媛妹妹
名媛妹妹 2021-01-06 01:54

I wish to make a Durandal custom dialog that adds a window frame with title and footer around an existing composable viewmodel.

I have made a customModal.html templa

1条回答
  •  隐瞒了意图╮
    2021-01-06 02:25

    I created a simplified example that you can use as starting point. It consists of an index view/vm that optionally opens an existing view/vm in a customModal. The existing view model is returned on close so that it's accessible.

    index.js

    define(function(require){
        "use strict";
    
        var app = require('durandal/app'),
            CustomDialog = require('./customModal'),
            Existing = require('./existingView'),
            ctor;
    
        ctor = function(){
            this.dialog;
        };
    
        ctor.prototype.showCustomModal = function(){
            this.dialog = new CustomDialog('My title', new Existing());
    
            this.dialog.show().then(function(response){
                app.showMessage('Model title "' + response.title + '".');
            });
        };
    
        return ctor;
    
    });
    

    index.html

    Durandal 2.0 custom dialog

    click here to open an existing view model in a custom dialog.

    customModal.js

    define(['plugins/dialog'], function (dialog) {
        var CustomModal = function (title, model) {
            this.title = title;
            this.model = model;
        };
    
        CustomModal.prototype.ok = function() {
             dialog.close(this, this.model);
         };
    
        CustomModal.prototype.show = function(){
           return dialog.show(this);
        };
    
        return CustomModal;
    });
    

    customModal.html

    existingView.js

    define(function () {
    
        var ctor = function () {
            this.title = 'I\'m an existing view';
        };
    
        return ctor;
    });
    

    existingView.html

    Live version available at http://dfiddle.github.io/dFiddle-2.0/#so/21821997. Feel free to fork.

    0 讨论(0)
提交回复
热议问题