我有以下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)"
更多推荐
发布评论