Skip to content

Instantly share code, notes, and snippets.

@laser
Created September 18, 2012 16:30
Show Gist options
  • Save laser/3744122 to your computer and use it in GitHub Desktop.
Save laser/3744122 to your computer and use it in GitHub Desktop.
Difference in callback arguments when publishing via "triggers" mechanism
// CollectionView + ItemView example
var MySubView = Marionette.ItemView.extend({
"triggers": {
"click .save": "widget:saved"
}
});
var MyCollectionView = Marionette.CollectionView.extend({
"initialize": function(options) {
this.bindTo(this, "itemview:widget:saved", this._onWidgetSaved, this);
},
"itemView": MySubView,
"_onWidgetSaved": function(view) {
// view is a reference to the ItemView in question
}
});
// Layout + ItemView example
var MyLayoutView = Marionette.Layout.extend({
"regions": {
"one": ".region.one"
},
"onRender": function() {
var subView = new MyItemView();
this.one.show(subView);
this.bindTo(subView, "widget:saved", this._onWidgetSaved, this);
},
"_onWidgetSaved": function(view) {
// view is undefined... in fact, arguments is empty
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment