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

Defining a can.Observe to achive automatic event handling in can.Control?

$
0
0
Hello.

I have a can.Observe and want to listen to it's changes in a can.Control using the "property-event-binding".
According to this thread it should be possible:

But in my case it does not fire the event. I think that it is defined in the wrong scope, so the Control does not know what "cat" is. This is my code:
  1. can.Observe "Cat",
  2.       init: (name) ->
  3.             @_super
  4.             name: name
  5.       toString: ->
  6.             @attr "name"

  7. can.Control "Testapp.Controller.Global",
  8.       init: (el, options) ->
  9.             @cat = new Cat "mittens"
  10.             @cat.attr "name", "nelly"
  11.       "{cat} name": (args...) ->
  12.             console.log args
The name change works on live binding to an EJS template but the event is not fired.
Does anyone know what has to be changed?

Thanks in advance,
Gammanator

Viewing all articles
Browse latest Browse all 3491

Trending Articles