0

我在一个视图中从另一个视图中看到了 post access 功能。如果我想将参数传递给 loadTaskPopup(param) 我该怎么做?

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 ?
 }
});
4

1 回答 1

2

您可以将其作为第二个参数传递给触发器:

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

在这种情况下,它是一个对象。你会收到这个loadTaskPopup

loadTaskPopup : function(params) {
  // params.param1 and params.param2 will have value1 and value2 respectively here.
}
于 2013-01-01T07:43:23.760 回答