Javascript Ember.js-打开模式操作赢得';不要从部件中冒泡

Javascript Ember.js-打开模式操作赢得';不要从部件中冒泡,javascript,ember.js,Javascript,Ember.js,我遵循了Ember.js,并在ApplicationRoute中放置了一个操作处理程序。在我尝试在组件的模板中使用相同的操作之前,这一切都很顺利,在这种情况下,它不会在控制台中执行以下错误:Uncaught error:Assertion Failed:JSBin的target,演示我的问题。请注意,在索引模板中指定的操作如何调用模态,而在组件中指定的操作却不调用模态。JSBin的要点如下: 索引模板 <!-- this creates the modal successfully --&

我遵循了Ember.js,并在
ApplicationRoute
中放置了一个操作处理程序。在我尝试在组件的模板中使用相同的操作之前,这一切都很顺利,在这种情况下,它不会在控制台中执行以下错误:
Uncaught error:Assertion Failed:JSBin的
target
,演示我的问题。请注意,在索引模板中指定的操作如何调用模态,而在组件中指定的操作却不调用模态。JSBin的要点如下:

索引模板

<!-- this creates the modal successfully -->
<button {{action "openModal" "modal-login"}}>open a modal (not in a component)</button>

<!-- this component has the same button as above in code, but clicking the button doesnt work -->
{{user-info}}
<button {{action "openModal" "modal-login"}}>open a modal(in a component)</button>

打开一个模态(不在组件中)
{{用户信息}}
用户信息组件模板

<!-- this creates the modal successfully -->
<button {{action "openModal" "modal-login"}}>open a modal (not in a component)</button>

<!-- this component has the same button as above in code, but clicking the button doesnt work -->
{{user-info}}
<button {{action "openModal" "modal-login"}}>open a modal(in a component)</button>
打开模式(在组件中)

我已经找到了一个解决方案,但是它非常粗糙,并且为我的组件添加了很多代码。在组件声明中,我复制了“OpenModel”操作,并使其通过组件上注册的操作发送操作。

您的修复是预期的行为,组件模板中触发的操作是由组件处理的。必要时,可以重定向操作,如指南示例所示

如果希望组件操作以控制器/路由约定流为目标,则必须将操作设置到组件本身中,而不是组件子视图中

 {{user-info tagName='button' 
   action='openModal' 
   context='modal-login' }}

您需要将操作发送到路由器操作。像这样:

App.UserInfoComponent = Ember.Component.extend({
  actions: {
        openModal: function(modalName) {
          console.log(modalName);      this.sendAction('openModal',modalName);
            }
        }
});
这是一个jsbin,包含工作解决方案:

这不起作用。。组件内部的模态仍然无法打开。