I have a series of buttons which when clicked display a popup menu positioned just below the button. I want to pass the position of button to the view. How can I do that?
As of backbone 1.1.0, the options argument is no longer attached automatically to the view (see issue 2458 for discussion). You now need to attach the options of each view manually:
MenuView = Backbone.View.extend({
initialize: function(options) {
_.extend(this, _.pick(options, "position", ...));
}
});
new MenuView({
collection: itemColl,
position: this.getPosition(),
...
});
Alternatively you can use this mini plugin to auto-attach white-listed options, like so:
MenuView = Backbone.View.extend({
options : ["position", ...] // options.position will be copied to this.position
});