本文介绍了如何使用关闭动作在路线上调用动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序路由上定义了 openModal 操作.我正在尝试从组件内部调用此操作.

I've got openModal action defined on application route. I'm trying to call this action from within a component.

如果我使用动作冒泡的语法:

If I use syntax for action bubbling:

{{my-component openModal="openModal"}}

然后一切都按预期进行,我可以使用 this.sendAction("openModal") 触发此操作.

then everything works as expected and I can trigger this action using this.sendAction("openModal").

但是,我不确定如何使用新的闭包语法获得相同的结果:

However, I'm not sure how to get the same result using the new closure syntax:

{{my-component openModal=(action "openModal")}}

在这种情况下,Ember 抱怨没有在控制器上定义操作 openModal.我是否必须在每个使用 my-component 的控制器上定义此操作?有没有办法以某种方式使用 target 选项告诉 Ember 这个动作是在路由上定义的?可以在单个组件中混合冒泡和闭包语法吗?

In this case, Ember complains that there's no action openModal defined on the controller. Do I have to define this action on every controller that uses my-component? Is there a way to somehow use target option to tell Ember that this action is defined on a route? Is it ok to mix bubbling and closure syntax in a single component?

我使用的是 Ember 2.0 beta 1.

I'm using Ember 2.0 beta 1.

推荐答案

除非在 Ember 或 2.7 中的某处引入可路由组件,否则不可能从路由传递关闭操作.

Until routable components are introduced somewhere in Ember or 2.7, it is impossible to pass a closure action from a route.

目前,您只能将关闭操作从控制器传递给子组件.

For now, you can only pass closure actions from a controller and on to child components.

UPD: Miko Paderes 暗示有一个插件可用:https://github.com/dockyard/ember-route-action-helper

UPD: Miko Paderes hints that an addon is available: https://github.com/dockyard/ember-route-action-helper

这篇关于如何使用关闭动作在路线上调用动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 12:29