How to pass parameters to a view

前端 未结 5 1343
梦谈多话
梦谈多话 2020-12-04 09:22

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?

5条回答
  •  北海茫月
    2020-12-04 09:58

    Use this.options to retrieve argumentr in view

     // Place holder
     
    var showNameView = Backbone.View.extend({ el:'.contentName', initialize: function(){ // Get name value by this.options.name this.render(this.options.name); }, render: function(name){ $('.contentName').html(name); } }); $(document).ready(function(){ // Passing name as argument to view var myName1 = new showNameView({name: 'Nishant'}); });

    Working Example: http://jsfiddle.net/Cpn3g/1771/

提交回复
热议问题