如何使用关闭操作在路由上调用动作? [英] How to call an action on a route using closure actions?

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

问题描述

我在应用程序路由上定义了 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 =(actionopenModal)}}

在这种情况下,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.1或2.2或2.3或2.4或2.5或2.6 或2.7中的某个地方引入可路由组件,无法通过关闭操作

Until routable components are introduced somewhere in Ember 2.1 or 2.2 or 2.3 or 2.4 or 2.5 or 2.6 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

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

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