听听Marionette ItemView以外的活动(Hear for event outside Marionette ItemView)

编程入门 行业动态 更新时间:2024-10-27 01:30:56
听听Marionette ItemView以外的活动(Hear for event outside Marionette ItemView)

我有以下HTML -

<html> <body> <div id="one"> <-- Marionette ItemView V1 rendered here --> </diV> <div id="two"> <-- Mariontette ItemView V2 rendered here --> </div> </body> </html>

如何在#two中的#one监听mouseup事件, #two #one :

var V1= Marionette.ItemView.extend({ template: "#template_for_div#one", event: { "mouseup #two": "do_something", // Other events }, // Other stuff });

I have the following html -

<html> <body> <div id="one"> <-- Marionette ItemView V1 rendered here --> </diV> <div id="two"> <-- Mariontette ItemView V2 rendered here --> </div> </body> </html>

How can I listen to mouseup event in #two within #one like so:

var V1= Marionette.ItemView.extend({ template: "#template_for_div#one", event: { "mouseup #two": "do_something", // Other events }, // Other stuff });

最满意答案

解决此问题的更好方法是创建两个对象都引用的dispatcher对象。 触发并侦听此对象上的事件。 (为了澄清,此对象现在是一个视图,而不是它是一个骨干事件对象,其唯一的工作是分派事件。)

Backbone文档在Backbone.Events部分说明了这一点: http : //backbonejs.org/#Events “例如,要创建一个方便的事件调度程序,它可以协调应用程序不同区域之间的事件:var dispatcher = _.clone( Backbone.Events)”

Better way to solve this problem is to create a dispatcher object that both objects have reference to. Trigger and listen to events on this object. (To clarify, this object is now a view, rather it is a backbone events object whose only job is to dispatch events.)

The Backbone docs say this under the Backbone.Events section: http://backbonejs.org/#Events "For example, to make a handy event dispatcher that can coordinate events among different areas of your application: var dispatcher = _.clone(Backbone.Events)"

更多推荐

本文发布于:2023-07-31 15:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1345289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ItemView   Marionette   event   Hear

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!