Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : event handling: this variable and arbitrary data

$
0
0

What I'm trying to accomplish is the following:

I have a "Globals" object that contains a number of variables, one of which is "NavigationState". In it, I store the active page, and any changes made to that are listened to by my "view" components. I have one component per view. A page consists of multiple views.

So anyway... NavigationControl updates NavigationState (in Globals), and I want my components to listen to changes in NavigationState.ActivePage. For this, I set each component's scope to contain a reference to NavigationState, via a "navState" variable in their scope.

Then, in each component, under "events", I do:

"{scope} navState" : function() {
   
somethingsomethingsomething...
}

...and this never seems to get called.

Before this however, I've tried Globals.getNavState().bind("ActivePage", <component_function_in_events>);
and listen to it with:

<component_function_in_events> : function(event, newVal, oldVal) { ....... }

Here, <component_function_in_events> got called, but the "this" object was set to event.target, not to the component itself.
Therefore, this.scope was "undefined".


Viewing all articles
Browse latest Browse all 3491

Trending Articles