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?
ItemView = Backbone.View.extend({ tagName: 'li', events: { 'click': 'showMenu' }, initialize: function() { _.bindAll(this, 'render'); }, render: function() { return $(this.el).html(this.model.get('name')); }, showMenu: function() { var itemColl = new ItemColl(); new MenuView({collection: itemColl}); // how to pass the position of menu here? } });
No, in SQL Server, we cannot pass parameters to a view. And it can be considered as one main limitation of using a view in SQL Server. Moreover, even if we try to pass parameters to a view, the SQL Server will return an error.
You can't pass a parameter to a view.
In the view use a cross join to the parameter table and put WHERE param_table. connection_id = CONNECTION_ID() . This will cross join with only one row from the parameter table which is what you want. You can then use the other columns in the where clause for example where orders.
You can't declare variables in a view.
You just need to pass the extra parameter when you construct the MenuView. No need to add the initialize
function.
new MenuView({ collection: itemColl, position: this.getPosition() })
And then, in MenuView
, you can use this.options.position
.
UPDATE: As @mu is too short states, since 1.1.0, Backbone Views no longer automatically attach options passed to the constructor as this.options, but you can do it yourself if you prefer.
So in your initialize
method, you can save the options
passed as this.options
:
initialize: function(options) { this.options = options; _.bindAll(this, 'render'); },
or use some finer ways as described by @Brave Dave.
Add an options argument to initialize
:
initialize: function(options) { // Deal with default options and then look at options.pos // ... },
And then pass in some options when you create your view:
var v = new ItemView({ pos: whatever_it_is});
For more information: http://backbonejs.org/#View-constructor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With