Can a Batman.Set of Batman.Object types be observed for changes?

69 views
Skip to first unread message

andrew.c....@gmail.com

unread,
May 2, 2013, 10:17:17 AM5/2/13
to batm...@googlegroups.com
Hi There

Say, we are given the following JSON data:

graphlist =
"graph1" :
"name" : "Graph 1"
"graph2" :
"name" : "Graph 2"

We then construct a Batman.Set of Batman.Objects in the following way:

a = new Batman.Set
for key, data of graphlist
a.add new Batman
"key" : key
"name" : data.name
"enabled" : true

Let's say we now save this in our controller. For example:

@set 'graphs', a

Now, in the (JADE driven) view, we can bind to an element

td(data-foreach-graph="controllers.graphcontroller.graphs")
input(type="checkbox",data-source="graph.enabled")

What if we wanted to observe any changes in the controller. I've tried adding this line to the controller ...

@observe 'graphs', (newVal, oldVal) ->
console.log "Value changed"

... and toggling the checkbox doesn't seem to trigger the callback.

Am I doing something wrong?

Thanks
Andrew

andrew.c....@gmail.com

unread,
May 2, 2013, 10:22:57 AM5/2/13
to batm...@googlegroups.com, andrew.c....@gmail.com

Sorry, I noticed that I made a mistake in my explanation. The JADE view uses "data-bind", and not "data-source". Regardless of which one I use, the callback doesn't seem to work.

Jeff Berg

unread,
May 2, 2013, 10:46:56 AM5/2/13
to batm...@googlegroups.com
Andrew,

You are going to need to call @observe on each object because the callbacks don't bubble up. The callback on the collection will only change if an item is added or removed.

Jeff



--
You received this message because you are subscribed to the Google Groups "batman.js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to batmanjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.





--
Jeff Berg
Owner/Developer
Ministry Centered Technologies
=================================
REVOLUTIONIZE the way you plan your SERVICES at planningcenteronline.com
REVOLUTIONIZE the way you plan your EVENTS at smartevents.com
Message has been deleted

andrew.c....@gmail.com

unread,
May 2, 2013, 10:51:45 AM5/2/13
to batm...@googlegroups.com, je...@ministrycentered.com
Hi Jeff

Thanks so much! I made the change and it's working now.

For the benefit of others, here's a brief controller code snippet that worked for me:

@get('graphs').forEach (t) ->
t.observe 'enabled', (oldVal, newVal) ->
console.log "hi"

Cheers
Andrew
Reply all
Reply to author
Forward
0 new messages