0

I saw the post access function in one view from another in backbone.js. If i want to pass parameter to loadTaskPopup(param) how can i do that ?

Backbone.View.prototype.event_aggregator = _.extend({}, Backbone.Events);

 window.PopupView = Backbone.View.extend({
   initialize: function() {
      _.bindAll(this, "loadTaskPopup");
      this.model = new PopupModel();
      this.event_aggregator.bind("tasks_popup:show", this.loadTaskPopup);
 },

 loadTaskPopup: function(param) {
    //do something with the parameter
 }
});

window.TaskbarView = Backbone.View.extend({
 loadTaskbarPopup: function() {
  this.event_aggregator.trigger("tasks_popup:show")     //How to pass parameter ?
 }
});
Community
  • 1
  • 1
user1184100
  • 6,742
  • 29
  • 80
  • 121

1 Answers1

2

You can pass it as a second parameter to the trigger:

this.event_aggregator.trigger("tasks_popup:show", {
  param1 : "value1",
  param2 : "value2"
});

In this case its an object. You'l receive this in loadTaskPopup.

loadTaskPopup : function(params) {
  // params.param1 and params.param2 will have value1 and value2 respectively here.
}
Cyclone
  • 1,580
  • 1
  • 8
  • 14