gpt4 book ai didi

Ember.js - 页面上的多个组件

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

我正在尝试构建一个 Ember 应用程序,但遇到了一些困难。

我有一个索引路由,我想渲染以下页面:

+--------------------------+
| Welcome, foo@bar.com |
+--------------------------+
| |
| New Posts |
| --------- |
| *foo |
| *bar |
| *baz |
| |
+--------------------------+

所以我有一个 Account 模型和一个 Post 模型。 (没有任何相关字段)

我在以下方面有概念上的困难:

Ember 路由有一个 model 方法,它返回路由的模型。但是,如果我希望多个模型与我的路线相关联怎么办?在本例中,我有 AccountPost。如何让它们对我的页面可用?

我尝试过的一件事是使用 setupController 并在 Controller 上手动设置 accountposts 以便模板可以访问它们.但是,如果我能做到这一点,那么 model 方法的意义/意义是什么!?

为什么 Ember 只想将路由与单个模型相关联?

感谢任何建议,

谢谢,丹尼尔

最佳答案

One thing I've tried is using setupController and manually setting account and posts on the controller so they can be accessed by the template.

你所做的是正确的,这就是 setupController Hook 的用途。

But if I can do this, what's the point/significance of the model method!? Why does Ember want to associate a route with only a single model?

RC3 中,阻止默认行为是不可能的。在 RC4 中,实现 setupController 钩子(Hook)可以防止默认行为的发生。对于迁移到较新版本的开发人员来说,这是一个潜在的重大变化。

另请注意,如果您的路由实现了 setupController Hook 并且您希望保留默认行为(model 也被调用),请确保调用 this._super() 来自 setupController Hook 。您可以阅读更多here在宣布的博客文章中。

希望对您有所帮助。

关于Ember.js - 页面上的多个组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18046115/

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