当可路由组件将来出现时,我一直期待着 Controller 的终结。因此,我一直将操作处理程序放入我的 route 。
// app/something/route.js
actions: {
doSomething() {
alert('action handled in route');
}
}
在我的模板中:
{{!-- app/something/template.hbs --}}
{{some-component action="doSomething"}}
在我的组件中:
{{!-- app/components/some-component/template.hbs --}}
<button {{action "onClickButton"}}>Click Me</button>
// app/components/some-component/component.js
actions: {
onClickButton() {
this.sendAction();
}
}
我应该处理 route 的操作并完全避免 Controller 吗?
最佳答案
由于 @locks 的输入, Controller 似乎不会消失。在 Ember 学习团队中。
根据his blog post :
Being future-proof does not mean never using any controller ever.
和
Generate controllers for all your routes.
你甚至可以在这个 git commit 中看到据 trek
报道,Ember 团队正在软化他们对 Controller 的立场。
所以,最后, Controller 很好用。这就是我要采取行动的地方。
关于ember.js - Ember 2.5 中的操作——路由还是 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37355559/