gpt4 book ai didi

ember.js - Ember 2.5 中的操作——路由还是 Controller ?

转载 作者:行者123 更新时间:2023-12-02 06:02:25 25 4
gpt4 key购买 nike

当可路由组件在 future 出现时,我一直在期待 Controller 的终结。所以我一直在我的 route 放置我的 Action 处理程序。

// 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 的 Action 并完全避免 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com