| Page 1 of 1 | [ 3 posts ] |
|
I can set up ModelList to bubble events like 'change' that occur on its contained models, and I can specifically attach an 'after' handler for a ModelList event, e.g. 'model.after('add', fn)', (where model is really a ModelList.)
I have not, though, been successful with the following: model.addTarget(this); this.after('add', fn); where 'this' is a View subclass. I never see fn() get called, even if it is defined inline. Does ModelList support bubbling its own events, like 'add'? Or does that only work if you attach an event listener directly? I've searched and every example seems to be about bubbling events for the models in the list, not the list events themselves. Thanks! Dave |
|
It's easier to describe this with code
Bubbling Model or ModelList events to a ViewClick here to see the revision history on this Gist. |
|
Thanks. Your code looks pretty similar to my own version (I took most of it from the User Guide for View), but I went ahead and tried yours anyway, and unfortunately, no go with a ModelList as the model.
Can you try your version where model is a ModelList, and try bubbling for the 'add' event of the ModelList? I've tried repeatedly and it fails, even with code identical to yours except that the model is a ModelList. Here's my current version Code: function defineJVMView(Y) { Y.JVMView = Y.Base.create('jvmView', Y.View, [], { // Specify delegated DOM events to attach to the container. events: { '#jvmTable button': {click: 'handleGraphButtonClick'}, '#jvmTable input[type=button]': {click: 'handleGraphButtonClick'} }, // runs when the view is instantiated. This is a good time to // subscribe to change events on a model instance. initializer: function() { var $this = this; // link us to changes in the selected JVM stats // subscribe to events when the model is replaced or any other // change events take place. var model = $this.get('model'); // if this view has a model, bubble model events to the view. model && model.addTarget($this); // if the model gets swapped out, reset targets accordingly. // We can make good use of this to switch the same // view among various model objects, rather than creating // a separate View object for each. $this.after('modelChange', $this.afterModelChange); // the following never actually calls afterAddChange. $this.after('model:add', $this.afterAddChange, $this); }, afterAddChange: function(ev) { console.log("JVMView's model 'add' called"); $this.render; }, afterModelChange: function(ev) { ev.prevVal && ev.prevVal.removeTarget($this); ev.newVal && ev.newVal.addTarget($this); console.log("JVMView's model has changed"); }, }, { ATTRS: { container: { value: '#jvmInfo' } } }); } With the above, afterAddChange never gets called, though the view is created with a ModelList for its 'model' attribute. Any ideas what might be wrong? Dave |
| Page 1 of 1 | [ 3 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group