从ItemView控件木偶泡沫事件父layoutview? [英] Marionette bubble event from itemview to parent layoutview?

查看:143
本文介绍了从ItemView控件木偶泡沫事件父layoutview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个区域的布局来看,该地区我有触发事件一个项目视图,但它似乎并没有被冒泡到布局视图。难道我做错了什么,或者这是设计的行为?我认为不添加ItemView控件preFIX父视图不是一个集合的看法?无论哪种方式,该事件永远不会冒泡到布局视图。

I have a layout view with a region, in that region I have a item view that triggers an event but it doesn't seem to be bubbled up to the layout view. Am I doing something wrong or is this designed behavior? I assume the itemview prefix is not added as the parent view is not a collection view? Either way the event is never bubbled to the layout view.

layoutView = Marionette.Layout.extend({
        template: "#layout-template",
        regions: {
            titleRegion: "#job-title-region"
        },
        triggers: {
            "save:clicked" : "onSaveClicked"
        },
        onSaveClicked: function (args) {
            alert('Clicked');
        }
    });

childview = Marionette.ItemView.extend({
        template: "#child-template",
        triggers: {
            "click .js-save": "save:clicked"
        }
    });

更新:

请参阅此琴 http://jsfiddle.net/7ATMz/11/ 我设法布局视图听孩子的事件,但我必须连线它的布局视图本身之外,打破封装。我反正这样做的布局视图?

See this fiddle http://jsfiddle.net/7ATMz/11/ I managed to get the layout view to listen to the child event but I have to wire it up outside of the layout view itself and break encapsulation. Can I do this in the layout view in anyway?

谢谢,

乔恩

推荐答案

触发器不太喜欢的工作是:你的布局正在使用他们错了。触发器是一种方便的给予一定的交互(例如点击)筹集的事件信号。

Triggers don't quite work like that: your layout is using them wrong. Triggers are a convenience to raise an event signal given a certain interaction (e.g. a click).

你想要的是使用triggerMethod(<一个href=\"https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.functions.md#marionettetriggermethod\">https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.functions.md#marionettetriggermethod)在布局触发功能。请参见 http://jsfiddle.net/ZxEa5/ 基本上,你想这在你的显示功能:

What you want is to use triggerMethod (https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.functions.md#marionettetriggermethod) to trigger a function in your layout. See http://jsfiddle.net/ZxEa5/ Basically, you want this in your show function:

childView.on("btn:clicked", function(){
  layout.triggerMethod("childView:btn:clicked"); 
});

而在你的布局:

onChildViewBtnClicked: function(){
   https://leanpub.com/marionette-gentle-introduction
});

事件冒泡只能用自动的收集发生?复合的观点,因为他们紧密结合自己的项目视图相关联。如果你想有一个布局,以监测其子视图之一,你需要设置了你自己。

Event bubbling only happens automagically with collection?composite views because they're tightly associated with their item views. If you want a layout to monitor one of its child views, you need to set that up on your own.

无耻插头:如果您想了解更多关于如何构建和清理code。与木偶,你可以看看我的书(<一href=\"https://leanpub.com/marionette-gentle-introduction\">https://leanpub.com/marionette-gentle-introduction)其中,这种类型的概念(以及它的应用程序)的更详细说明。

Shameless plug: if you want to learn more about how to structure and clean up your code with Marionette, you can check out my book (https://leanpub.com/marionette-gentle-introduction) where this type of concept (and its applications) is explained in more detail.

这篇关于从ItemView控件木偶泡沫事件父layoutview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆