HotTowel Durandal Inject different views based on the user

依然范特西╮ 提交于 2019-12-07 12:01:23

It's possible to return a 'viewUrl' property in the view model, so hopefully something like the following will crack the door open ;-).

define(function () {
    viewUrl = function () {
        var role = 'role2'; //Hardcoded for demo

        var roleViewMap = {
            'default': 'samples/viewComposition/dFiddle/index.html',
            role1: 'samples/viewComposition/dFiddle/role1.html',
            role2: 'samples/viewComposition/dFiddle/role2.html'
        };

        return roleViewMap[role];

    }

    return {
        viewUrl: viewUrl(),
        propertyOne: 'This is a databound property from the root context.',
        propertyTwo: 'This property demonstrates that binding contexts flow through composed views.'
    };
});

Did you take a look at John Papa's JumpStart course on PluralSight.

Look at the source code from that app here: https://github.com/johnpapa/PluralsightSpaJumpStartFinal

In App/Config.js file he adds other routes which are visible by default as :

 var routes = [{
        url: 'sessions',
        moduleId: 'viewmodels/sessions',
        name: 'Sessions',
        visible: true,
        caption: 'Sessions',
        settings: { caption: '<i class="icon-book"></i> Sessions' }
        }, {
        url: 'speakers',
        moduleId: 'viewmodels/speakers',
        name: 'Speakers',
        caption: 'Speakers',
        visible: true,
        settings: { caption: '<i class="icon-user"></i> Speakers' }
        }, {
        url: 'sessiondetail/:id',
        moduleId: 'viewmodels/sessiondetail',
        name: 'Edit Session',
        caption: 'Edit Session',
        visible: false
    }, {
        url: 'sessionadd',
        moduleId: 'viewmodels/sessionadd',
        name: 'Add Session',
        visible: false,
        caption: 'Add Session',
        settings: { admin: true, caption: '<i class="icon-plus"></i> Add Session' }
    }];

You can add routes to both the views here using the same logic and then in your productEditor.js you can decide which view to navigate and navigate to that using router.navigateTo() method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!