我试图在木偶项目视图(List.SendQuestion)中触发一个事件,但是,我无法在控制器中注册触发器(如下所示)
本质上,在单击“a.send”后,应该会发生触发器,并且“send_qn_view”应该捕获事件并打印出“已触发”消息。但那并没有发生。
有人可以告诉我这里可能出了什么问题吗?
@Dailymuses.module "SidebarModule.List", (List, App, Backbone, Marionette, $, _) ->
List.Controller =
showSidebar: ->
send_qn_view = new List.SendQuestions
collection: Onethingaday.Public.friends
send_qn_view.on "itemview:ask:user", (itemview, question) ->
console.log('triggered') #THIS IS NOT EXECUTED
class List.SendQuestion extends Marionette.ItemView
template: "sidebar/list/templates/send_question"
className: 'qn_askee'
tagName: 'li'
events:
"click a.send" : "sendQuestion"
sendQuestion: (e) ->
e.preventDefault()
debugger #this debugger was triggered
@trigger "ask:user", @model
class List.SendQuestions extends Marionette.CompositeView
template: "sidebar/list/templates/send_questions"
itemView: List.SendQuestion
itemViewContainer: "ul.friends"