我有一个可能从不同的路由/模板触发的操作,但最终应该发送到应用程序 Controller 中的一个操作。我该怎么做呢?我只看过 needs
的例子用于向子 Controller 发送 Action 的属性。
那么如何从 /posts/post
发送 Action ?和 /
(应用程序)都被发送到应用程序 Controller ?
最佳答案
您通常将 ApplicationRoute 中的操作处理程序定义为:
App.ApplicationRoute = Em.Route.extend({
actions: {
print: function() {
console.log('hello');
}
}
});
然后,如果您的操作未在 Controller 或特定路由上定义,则该操作将冒泡到任何父路由,直到 ApplicationRoute。
如果要在路由和应用程序级别处理操作,则必须在操作处理程序中返回 true,以便操作可以冒泡。
App.IndexRoute = Em.Route.extend({
actions: {
print: function() {
console.log('hello');
return true;
}
}
});
检查 guide详细说明。
关于ember.js - 如何将 Action 发送给父 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23784511/