これは私が持っている単純なバックボーン ビュー クラスです。
class Student.Views.SharedChat extends Backbone.Marionette.ItemView
template: 'student/shared/chat/chat'
onRender: ->
Student.CurrentUserChannel.bind('student:chat_threads:created', @setUpThread)
setUpThread: (data) ->
channel = Student.Pusher.subscribe("presence-thread-1")
channel.bind('student:chat_messages:created', @newMessage)
newMessage: (data) ->
do something with data...
end
私の質問は、上記のコードがどのように見えるかから、@newMessage を呼び出す方法です。@newMessage へのチャネル バインディングはそのスコープ内でそれを認識しません。そのバインディングから newMessage 関数にアクセスするにはどうすればよいですか?
あなたの返信に感謝します。これは私を壁に押し付けているようなものです。
以前にファットアローを試したことがありますが、完全には理解していなかったと思います。niko の返信を読んで、もう少し考えさせられました。問題は、@setUpThread 自体が既にバインドされている関数として呼び出されていたため、太い矢印は @newMessage ではなく @setUpThread が @ を維持するためのものである必要があったことです。