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

Re : Listen for change on model List aliased to controls options object

$
0
0
For the control to listen to events using the "{property} change" syntax, property must be defined on this.options before the controller's init() gets called.

One way to ensure it's in the right place before init() is to set it inside setup():
  1. can.Control.extend({
  2.       setup: function($el, options) {
  3.             options.stateParams = options.data.stateParams;
  4.             options.foo = options.foo || defaultValueFromSomewhere;
  5.             // etc. Whatever logic you need to fill in options.yourProperty

  6.             // make sure to call the parent's setup(), or bad things will happen
  7.             return this._super.apply(this, arguments);
  8.       },
  9.       // etc

  10.       // Then, so long as stateParams and foo are observable:
  11.       '{stateParams} change': function() { ... },
  12.       '{foo} change': function() { ... }
  13. });

Edit: Oops -- apparently the parent's setup() is responsible for setting up the event bindings for "{property} change" callbacks, not init() as I thought above. This is mentioned at the bottom of the docs for setup().


Viewing all articles
Browse latest Browse all 3491

Trending Articles