events - Backbone listenTo not working -
i have following working code, , planning replace object.on calls object.listento calls:
setfield: function(field) { if (this.field) this.field.off(null, null, this); if (field) { this.field = field; this.field.on('validate', this.rendererrors, this); } return this; },
and new version
setfield: function(field) { if (this.field) this.stoplistening(this.field); if (field) { this.field = field; this.listento(this.field, 'validate', this.rendererrors); } return this; },
but how it's not working. method this.rendererrors no being called second version.
the strange thing updated al rest of app accordingly without trouble.
i'm sure there must pretty silly i'm missing.
btw, code used field raise event
[...] this.trigger('validate', this.errors); this.error = !this.isvalid(); return this.errors; },
i haven't used new listento , stoplistening yet, can see in new version, you're calling stoplistening against parameter field
, meaning view still listening previously-visible this.field
setfield: function(field) { if (this.field) this.stoplistening(field);
your existing version calls off
on this.field
.
try using:
if (this.field) this.stoplistening(this.field);
Comments
Post a Comment