javascript - Backbone: Best way to handle variable common to all models -


i'm developing first backbone single page app project , i'm facing issue.

basically have menu (html select input element) implemented view. value used control pretty every other data requests since specifies kind of data show in other views.

right handle dom event , trigger global event every model can catch , keep track internally of new value. that's because value needed when requesting new data. doesn't solution because a) end writing same function (event handler) in every model , b) several models same variable.

var metrics = backbone.collection.extend({     url: "dummy-metrics.json",     model: metricsitem,      initialize: function () {         this.metric = undefined;     },      setmetric: function (metric) {         this.metric = metric;         globalevents.trigger("metric:change", this.get(metric));     } });  var globalcomplexity = backbone.collection.extend({     url: function () {         var url = "http://asd/global.json?metric=" + this.metric;         return url;     }, //"dummy-global.json",     model: globalcomplexyitem,      initialize: function () {         this.metric = undefined;          this.listento(globalevents, "metric:change", this.updatemetric);     },      updatemetric: function (metric) {         this.metric = metric.get("id");         this.fetch({ reset: true });     } }); 

all other collections structured globalcomplexity.

what's cleanest way solve problem?

thank much.

define global parametersmanager. export instance (singleton) require when need it.

on "globalupdate" update parametersmanager trigger "update" model/collections they'll current parameters in parametersmanager.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -