backbone.js悬停在root dom上不起作用

时间:2011-09-23 06:46:56

标签: javascript backbone.js coffeescript

为什么悬停事件绑定在根dom上不起作用?虽然默认情况下,我可以将<div class="activity span"></div>放在模板周围,并在外面放置包装<div></div>,但它很糟糕。
请帮忙~thx

ActivityView = Backbone.View.extend(
    className: "activity span"
    events: {
        "hover" : "toggleSidebarTrigger"   // doesn't work..
        "hover img" : "foo"                // works
        "click" : "bar"                    // works
    }
    template: _.template($("#activity-item-template").html())
    initialize: ->
        this.model.bind("change", this.render, this)
        this.render()
    render: ->
        $(this.el).html(this.template(this.model.toJSON()))
    toggleSidebarTrigger: ->
        this.$(".sidebar-trigger").toggle()

)


  <script id="activity-item-template" type="text/template">
      <img src="{{ photo.url_m }}" class="activity-media" alt="" />
      <a href="#toggle-sidebar" class="sidebar-trigger"><%= image_tag "plus_69x69.png" %></a>
  </script>

1 个答案:

答案 0 :(得分:0)

ActivityView = Backbone.View.extend(
    className: "activity span"
    events: {
        "hover" : "toggleSidebarTrigger"   // doesn't work..
        "hover img" : "foo"                // works
        "click" : "bar"                    // works
    }
    template: _.template($("#activity-item-template").html())
    initialize: ->
        this.model.bind("change", this.render, this)
        this.render()
    render: ->
        $(this.el).html(this.template(this.model.toJSON()))
    toggleSidebarTrigger: ->
        $(".sidebar-trigger", this.el).toggle()

)

尝试这个..