HotTowel Durandal根据用户注入不同的视图 [英] HotTowel Durandal Inject different views based on the user

查看:108
本文介绍了HotTowel Durandal根据用户注入不同的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HotTowel模板的 shell.html 中,我们有:

In the shell.html for HotTowel template we have:

    <!--ko compose: {model: router.activeItem, 
        afterCompose: router.afterCompose, 
        transition: 'entrance'} -->
    <!--/ko-->

将按惯例自动插入正确的视图。我试图根据用户在HotTowel / Durandal应用程序中的角色注入不同的视图。例如,
我有两个视图,

which will automatically insert the proper view by convention. I am trying to inject different views based on the user's role in a HotTowel/Durandal App. For example, I have two Views,


  1. productEditor_Admin.html

  2. productEditor_Superviser。 html
    (而不是这两个视图,我以前只有productEditor.html,按照惯例一切正常)

和只有一个ViewModel:

and only a single ViewModel:


  1. productEditor.js

现在,我希望在 productEditor.js 中有一个函数,让我根据用户的角色决定插入哪个视图。我在撰写文档中看到,我们可以执行功能策略(设置):承诺但我不确定在HotTowel模板中实现此目的的最佳方法是什么。有人已经试过并得到了答案吗?

Now, I want to have a function in productEditor.js that will let me decide which view to insert based on user's role. I see in the Composition documentation, we can do function strategy(settings) : promise but I am not sure what's the best way to accomplish this in the HotTowel template. Anyone have already tried and got an answer for that?

推荐答案

可以在视图模型中返回'viewUrl'属性,所以希望以下内容会打开门; - )。

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.'
    };
});

这篇关于HotTowel Durandal根据用户注入不同的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆