5
events:
    'click textarea': 'composeComment'
    'click .submit': 'submit'
    'blur textarea': 'textareaBlur'
    'resize article': 'repositionBoards'


repositionBoards: ->
    #this is my own function, i just need it to be called everytime an article's size changes
    board.align()

repositionBoardsサイズ変更イベントでメソッドを呼び出すにはどうすればよいですか?

4

1 に答える 1

8

resizeイベントはに送信されますwindow

ブラウザウィンドウのサイズが変更されると、イベントが要素に送信resizeされますwindow

ただし、バックボーンビューのイベントは、ビューのelusingにバインドされますdelegate。ビューはイベントをel取得しないため、ビューを挿入しても効果はありません。resize'resize articule': 'repositionBoards'events

ビューでイベントを取得する必要がある場合は、それを自分自身resizeにバインドする必要があります。window

initialize: (options) ->
    $(window).on('resize', this.repositionBoards)
remove: ->
    $(window).off('resize', this.repositionBoards) # Clean up after yourself.
    @$el.remove() # The default implementation does this.
    @
repositionBoards: ->
    # Use => if you need to worry about what `@` is
    board.align()

また、ハンドラーremoveのバインドを解除できるように、が追加されていることに注意してください。resizeもちろん、view.remove()ビューを削除するために使用するか、そのビューがアプリケーション全体であるかどうかを気にする必要はありません。

于 2012-06-28T23:32:56.413 に答える