Simple collection-view binding

78 views
Skip to first unread message

Murray Spork

unread,
Apr 24, 2013, 4:32:17 PM4/24/13
to chapl...@googlegroups.com
Hi,

I want to get the simplest version of binding a view to a successful fetch() event for a collection. I have this working with syncmachine - but for my understanding I want to compare this to not using syncmachine. 

This post from Mathias last year mentions how to manually bind the view to change events in the model:

class CartView extends View 
   initialize: -> 
     super 
     @modelBind 'change', @render 
 
After some investigation I find that modelBind has been removed - so I'm trying to figure out how to do this using event delegation in View instead.  Here is what I tried:

  class NotesView extends View
    listen: 
      'change collection': 'render'

I also tried: 

  class NotesView extends View
    initialize: ->
      super
      @listenTo @collection, 'change', 'render'

Can anyone tell me what I'm doing wrong? The view does not render - obviously the I did not subscribe to the event properly. 

Thanks in advance
Murray

Murray Spork

unread,
Apr 24, 2013, 4:34:19 PM4/24/13
to chapl...@googlegroups.com
PS - I'm expecting the change event to propagate after collection.fetch() finishes - I call fetch from the constructor for my collection:

  class Notes extends Collection

    url: 'api/notes'

    model: Note

    initialize: -> 
      super
      @fetch()

Paul Miller

unread,
Apr 25, 2013, 12:55:08 PM4/25/13
to chapl...@googlegroups.com
does it work if you don’t redefine initialize and call fetch manually?

Murray Spork

unread,
Apr 25, 2013, 4:18:25 PM4/25/13
to chapl...@googlegroups.com
On Thursday, April 25, 2013 9:55:08 AM UTC-7, Paul Miller wrote:
does it work if you don’t redefine initialize and call fetch manually?

Thanks Paul.

Tried that but get the same result. 

So I changed the event I'm listening for to "add" - and now the table renders correctly. 

I would presume this will end up triggering render for each model that is added to the collection?

Is there an event I can listen for that is only triggered when fetch completes successfully? Where is the best place to look for documentation on what events are raised?

Thanks
Murray

Paul Miller

unread,
Apr 26, 2013, 2:55:05 AM4/26/13
to chapl...@googlegroups.com
try ‘sync’ event http://backbonejs.org/#Events-catalog
Reply all
Reply to author
Forward
0 new messages