3

我的外壳有按钮,只有当用户当前正在查看某个视图模型时才应该显示这些按钮。如何从 shell 中确定视图当前是否“活动”?

4

1 回答 1

8

假设路由是在shell.js activatethen using中定义的,viewAttached将允许访问该router对象。

return {
    router: router,
    viewAttached: function () {
        console.log('activeRoute', router.activeRoute());
    },
    activate: function () {
        router.map([...

根据评论更新

在 Durandal 2.xactiveRoute()中不再定义。改为使用router.activeInstruction()

根据评论更新 2

在 Durandal 2.xviewAttached现在是attached.

注意:对于那些需要访问当前路由的配置以获取自定义属性或其他信息的人,您可以通过 router.activeInstruction() 访问原始数据,该指令包含片段、queryString、params 和 queryParams。它还包含一个配置属性,该属性与您的原始路由配置相同。

http://durandaljs.com/documentation/Conversion-Guide/

于 2013-05-20T09:57:38.393 回答