Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How deep can I nest backbone change events?

Say I have a (rather ridiculous) book model who attributes look something like:

page:{
    paragraph:{
        wordcount: {
            the: 8,
            at: 10
        }
    }
}

can I bind to change of very nested values like so?

book.on("change:page:paragraph:wordcount:the", ...);
like image 483
fancy Avatar asked May 01 '12 19:05

fancy


1 Answers

Backbone only triggers change events for top-level attribute names. Per the Catalog of Events:

  • "change" (model, options) — when a model's attributes have changed.
  • "change:[attribute]" (model, value, options) — when a specific attribute has been updated.

There's no mention of any nesting there. In fact, if you do change a nested property of the attribute, I'm pretty sure it won't even trigger an event (since the attribute itself didn't change). Additionally, if you look at the annotated source (although the factors affecting this behavior are a bit split up) you can follow it down to where change:attribute events are triggered.

However, it does look like there's a plugin to help accomplish what you're after.

like image 85
Rob Hruska Avatar answered Sep 28 '22 09:09

Rob Hruska