javascript - EmberJS:强制转换到父路由
问题描述
我有两条路线:一条名为 的主路线parent
和一条名为 的子路线parent.child
。当在 中发生某些事情(我们称之为X)时parent.child
,我想过渡到parent
,但由于技术上我们已经在那里,Ember 什么也不做。
// 'parent.child' controller
this.transitionToRoute('parent');
所以我想知道是否有办法强制这种“过渡”。原因是其中的代码需要在X发生parent
后重新运行。
解决方案
你可以调用refresh
你的父路由。
现在,在父路由上调用动作的最简单方法是定义一个,然后send
在控制器上使用让动作冒泡。
所以你的父路线:
class ParentRoute extends Route {
@action
refreshParent() { // dont name it refresh because of the naming conflict
this.refresh();
}
}
和你的孩子控制器:
class ChildController extends Controller {
@action
refreshParentRoute() { // again, another name
// this will first look for a `refreshParent` action on this controller,
// then the `child` route and last the `parent` route.
this.send('refreshParent');
}
}
推荐阅读
- html - 有没有办法模仿
- android - 试图在我的手机上安装一个简单的 kivy 应用程序,但收到 buildozer last 命令错误消息
- android - 为什么我的应用程序被检测为病毒?它发生在更新 SDK 版本和 Adsense 之后
- python - 检查python中排列的有效性
- php - Moodle 1.8.1 PHP 问题
- html - 我想从名为“se_component_wrap sect_dsc __se_component_area”的特定 div 类中提取 html
- logic - 如何将 Coq 用作计算器或前向链接规则引擎/序列应用工具?
- woocommerce - 从 Woocommerce 电子邮件通知中隐藏重力形式字段标签
- python - 如何在 Windows 10 上沙箱学生的 Python 3 代码提交以进行自动作业评估?
- c# - 如何在没有互联网的情况下在树莓派上包含 nuget 包?