我有一系列按鈕,點擊後會顯示一個位於按鈕下方的彈出菜單。我想將按鈕的位置傳遞給視圖。我怎樣才能做到這一點?如何將參數傳遞到視圖
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?
}
});
此不再工作爲1.1.0:「骨幹查看不再自動連接傳遞給構造選項'this.options',但你可以,如果你喜歡自己做。」(HTTP:// backbonejs。組織/#更新日誌)。 –
現在要獲得相同的行爲:http://stackoverflow.com/a/19325531/941764 – jgillich
這工作完全,只需添加參數在您看來初始化方法:初始化:功能(選擇){ 警報(options.position) ; } –