gpt4 book ai didi

javascript - HotTowel Durandal 根据用户注入(inject)不同的 View

转载 作者:行者123 更新时间:2023-11-30 13:03:44 24 4
gpt4 key购买 nike

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

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

这将按照惯例自动插入正确的 View 。我正在尝试根据用户在 HotTowel/Durandal 应用程序中的 Angular 色注入(inject)不同的 View 。例如,我有两个 View ,

  1. productEditor_Admin.html
  2. productEditor_Superviser.html(而不是这两个 View ,我曾经只有 productEditor.html,按照惯例一切正常)

并且只有一个 ViewModel:

  1. productEditor.js

现在,我想在 productEditor.js 中添加一个函数,让我根据用户 Angular 色决定插入哪个 View 。我在 Composition documentation 中看到,我们可以执行 function strategy(settings) : promise 但我不确定在 HotTowel 模板中完成此操作的最佳方法是什么。有人已经尝试过并得到答案了吗?

最佳答案

可以在 View 模型中返回一个 'viewUrl' 属性,所以希望像下面这样的东西能打开大门 ;-)。

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

关于javascript - HotTowel Durandal 根据用户注入(inject)不同的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16471362/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com