1

I have event and function pairs like this ..

events : {

  'click #category' : 'categoryList',
}

My function needs argument result set to be passed in .

 categoryList: function(rs){
   this.modelmaker(rs);
  var array = JSON.parse('['+ arraymodels +']');
  makeList(array,'ProdCat',function(html){$("#listofstuffs").append(html);});
  alert(collection.length);
      },

if i try to give categorylist(rs) as function value in event function pair it says function is not defined .!

there should be some questions already explaining about this kind of trivial doubts but i don't even know the apt keywords to search for. every example i see in event binding ; i find no argument passed. some one Please help me out.

Prasanna
  • 440
  • 4
  • 14
  • elements of answer here http://stackoverflow.com/questions/11174125/passing-arguments-to-events-in-backbone – Bill'o Mar 25 '14 at 11:10

1 Answers1

0

The value in your events hash can be a function definition. Thus you could do:

events: {
    'click #category': function() { this.categorylist('somearg'); }
}

This will work if you want the same argument passed in every time. If you need arguments related to the element clicked, I can suggest adding a data attribute in the html, and retrieving it from event.target in the function.

arbuthnott
  • 3,819
  • 2
  • 8
  • 21