Reputation: 7792
The code that I have a question spans multiple pages, so I'll do my best to post what's relevant.
I've created a table using d3, and on click, I'm changing a model. The method that I'm using to change the method is below -
setSelected:()->
@set
selected:true
console.log("SELECTED CALLED")
@trigger "selected"
@
I know in console that SELECTED CALLED is being printed.
Now, in the initialize function for my view, I've done this -
initialize:()->
@columnHeadings = @options.columnHeadings
@columns2Display = @options.columns2Display
@outerTable = @options.outerTable
@model.on "selected", @select()
@model.on "unselected",@deselect()
Now, select looks like this -
select:()=>
console.log "SELECTED"
console.log(@model)
SELECTED is never printed, which leads me to believe that either Backbone doesn't know which view(there is a view per model, which is also a 'row' view), corresponds to which model, or I'm making a syntax error.
Thanks
Upvotes: 0
Views: 119
Reputation: 434665
When you say this:
@model.on "selected", @select()
@model.on "unselected", @deselect()
you're calling the @select
and @deselect
methods and binding their return values to the events. The parentheses make them method calls rather than the method references that you want. So just drop the parentheses to bind the method references:
@model.on "selected", @select
@model.on "unselected", @deselect
Upvotes: 1