Question

I need to perform an action after switching to a view.

The first time you switch to a view 'activate' and then 'compositionComplete' is called.

After that only 'activate' is called.

It would appear that 'activate' is called before the view has finished being displayed and this is causing issues with a JavaScript control I'm using (Bing Maps V7).

I've been using Hooking Lifecycle Callbacks as a reference but there doesn't appear to be a suitable callback to hook in to.

Is there another event or approach I can use to tell when the DOM has finished changing to the view?

Was it helpful?

Solution

It sounds as though your module is a singleton instead of an instance. Is that true? If you create an instance-based module, the module will be created anew each time it's activated. That will cause the compositionComplete to re-execute.

The activate handler is good for preparing data that will ultimately be displayed in the view. compositionComplete is best for handling matters that depend on a fully-constructed DOM.

We use Bing Maps AJAX v7 as well, and I've always placed it in an instance-based module.

To create an instance-based module, if you're not familiar, make sure your viewmodel returns a constructor function instead of an object literal.

OTHER TIPS

Have you tried placing the Bing initialization in attached? Or creating a custom binding for it? Any third party libraries i use will always be initialized in attached, and if its something i want to use more than once, ill either create a custom binding for it or create a widget.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top