Tuesday 15 July 2014

javascript - backbone model - howto execute outer functions from event handlers? -


In backbone, is it possible to start event handlers in a loop when handlers use functions in external models?

For example, how can I get something to work like below?

  var MyModel = Backbone.Model.extend ({eventHandlers: {panic: function (e) {this.myErrorHandler (e); // (My_bj [key] = value;}, this );}, MyErrorHandler: function (e), I {Console.error ('my error handler', e);}});   

How do I call a model handler function (EarhardHandler) from an event handlers which is declared in a sub-object? Or is there any other way to achieve this?

TIA

Do you mean each handler on the defined event by your key To execute, is the model bound for example?

  var MyModel = Backbone.Model.extend ({eventHandlers: {error: function (e) {this.myErrorHandler (E); // does not work}}, launch: function ( } {Var _this = this; _.each (this.eventHandlers, function (value, key) {_this.on (key, _ (value) .bind (_this))}}}}, myErrorHandler: function (e) {Console.error ('my error handler', e);}});   

But what if you want many handlers for the same event?

No comments:

Post a Comment