如何设置Backbone视图事件?

时间:2015-05-19 16:54:04

标签: javascript backbone.js coffeescript underscore.js

问题: 我有一个基于Backbone,Underscore,Browserfy和coffeescript的项目。 项目中有一个视图:

"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>
'

渲染完美正常,但事件(查看事件)无法正常工作。请帮助我做它的工作。请将您的答案基于我的代码。

0 个答案:

没有答案