Durandal: Showing a 'LOADING…' during composition

后端 未结 2 1621
执笔经年
执笔经年 2020-12-30 09:47

I can easily show a loading message while the activate method is doing its thing like so:

        
<
相关标签:
2条回答
  • 2020-12-30 10:02

    This begs for a comment of 'what have you tried?' but given that I could see the benefit of this for future users I wanted to throw in my $0.02 -

    The splash displays on your screen until Durandal loads up the application and replaces the div with id="applicationHost" 's content with the shell view and the subsequent views that are loaded. If you wanted to make this a re-usable component one thing that you could do is to take that Html.Partial view that is being loaded and create your own view inside of your app folder in your Durandal project.

    For example you would create a new HTML view inside of your app folder -

    splashpage.html

    <div class="splash">
        <div class="message">
            My app
        </div>
        <i class="icon-spinner icon-2x icon-spin active"></i>
    </div>
    

    And then compose it from your shell -

    <div data-bind="if: showSplash">
        <!-- ko compose: 'splashpage.html' -->
        <!-- /ko -->
    </div>
    

    And in your view model you would toggle the observable showSplash whenever you want to show / hide it -

    var showSplash = ko.observable(false);
    
    var shell = {
        showSplash: showSplash
    };
    return shell;
    

    And you could call that from your activate methods inside your other view models like this -

    define(['shell'], function (shell) {
    
        function activate() {
            shell.showSplash(true);
            // do something
            shell.showSplash(false);
        }
    
    });
    
    0 讨论(0)
  • 2020-12-30 10:08

    This sounds to me like a scenario where a custom transition may be useful. When the composition mechanism switches nodes in and out of the DOM, it can use a transition.

    This page, under Additional Settings>Transition (about halfway down) describes a custom transition: http://durandaljs.com/documentation/Using-Composition/

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