I have a Durandaljs application. I want to have a back button in shell view that should be hidden depends on which view is activated now. What is the easiest way to detect navigation event in shell viewmodel to change back button visibility state?

有帮助吗?

解决方案

Basic Solution

You can check what view is activated using router via router.navigationModel()[x].isActive

Application Messaging

You can in the Activation event of ViewModel use Durandal Application-Wide Messaging

In view model in Activate function include

app.trigger('viewNavigated', isBackVisable);

While in shell view model

app.on('viewNavigated').then(function(isBackVisable)
{
     if(isBackVisable)
          MakeButtonBackVisable();
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top