gpt4 book ai didi

events - 事件未在 Marionette Itemview 中触发

转载 作者:行者123 更新时间:2023-12-01 07:40:36 26 4
gpt4 key购买 nike

我试图在 Marionette itemview (List.SendQuestion) 中触发一个事件,但是,我无法在 Controller 中注册触发器(如下所示)

本质上,在单击“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"

最佳答案

编辑:更正了我的答案并更新了我的 fiddle

对于那个很抱歉。您的事件冒泡语法是正确的。
https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.collectionview.md#childview-event-bubbling-from-child-views

"itemview:*" event bubbling from child views

When an item view within a collection view triggers an event, that event will bubble up through the parent collection view with "itemview:" prepended to the event name.

That is, if a child view triggers "do:something", the parent collection view will then trigger "itemview:do:something".



有什么需要注意的。 Marionette 支持 View 触发器。如果您的回调只是触发 View 事件,您可以删除事件哈希和回调并将代码缩短为:
triggers: {
"click a.send": "ask:user"
}

http://lostechies.com/derickbailey/2012/05/15/workflow-in-backbone-apps-triggering-view-events-from-dom-events/

fiddle :
http://jsfiddle.net/FRHkt/1/

关于events - 事件未在 Marionette Itemview 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16313946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com