Answer the question
In order to leave comments, you need to log in
How to set up Backbone view events?
Good evening. Essence of the question:
There is a project using backbone, underscore, browserfy and coffeescript
There is a view in this project:
"use strict"
_ = require "underscore"
$ = require "jquery"
Backbone = require "backbone"
Works_tpl = require "modules/works/templates/works_template.coffee"
module.exports = Backbone.View.extend
el : ".works-wrapper"
template: _.template Works_tpl
events : {
"click .change-view__item": "changeView"
}
initialize: (works, type = "list")
@render works, type
return
render: (works, type) ->
@$el.html @template
return
changeView: ->
console.log 123
return
"use strict"
module.exports = '
<div class="change-view__item">Нажми на меня</div>
'
Answer the question
In order to leave comments, you need to log in
You need to call @delegateEvents at some point (preferably after @el has content.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question