[英]Ember 2 - Loading Nested Route in parent route
I have two routes: 我有两条路线:
/users/:user_id
(aka user
) /users/:user_id
(又名user
) /users/:user_id/roles
(aka user roles
) /users/:user_id/roles
(又称user roles
) I now want to show the user roles
within the user
route. 我现在想要在
user
路由中显示user roles
。 I still want to have a separate user roles
route. 我仍然希望有一个单独的
user roles
路由。
When user roles
are being loaded within the user
route, the page should show the user roles
section/template as loading
(Because of requests to the server for user_roles
should continue to be separate, I don't want to load user_roles (ajax)
from within the user
route because it will slow down the route loading). 当
user roles
被在中加载user
的路线,该页面应显示user roles
的部分/模板loading
(因为请求到服务器的user_roles
应继续独立,我不希望加载user_roles (ajax)
从在user
路由中,因为它会减慢路由加载)。
How do I achieve this? 我该如何实现这一目标?
user-roles-component
, and feed user
into it like so: {{user-roles-component user=user}}
. user-roles-component
的异步组件,并将user
输入其中: {{user-roles-component user=user}}
。 Then I can use this component on both of my routes. user roles
route, I won't be loading model?. user roles
路由的情况下,我不会加载模型? And I will not be violating DDAU since I will be dealing with user_roles
data directly in my component. user_roles
数据。 user-roles-service
that deals with asynchronous loading of user_roles
given the user
and also pass it in both routes and render using a custom component that will be in both of the routes. user-roles-service
,该user-roles-service
处理给定user
的user_roles
异步加载,并在两个路由中传递它,并使用将在两个路由中的自定义组件进行渲染。 I'd create a loading state within your route and load the content of roles once you click in one button/link and pass that received content to your component. 我会在您的路线中创建一个加载状态 ,并在您单击一个按钮/链接并将收到的内容传递给您的组件后加载角色的内容。
An alternative is to create a loading state in your component as well (and probably the way I'd do). 另一种方法是在组件中创建加载状态(可能就像我做的那样)。 To do that you would receive an
Promise
from your ajax request (there are several ways to do that: .find()
, .query()
, ember-ajax
, ember-network
). 要做到这一点,你将从你的ajax请求中收到一个
Promise
(有几种方法可以做到这一点: .find()
.query()
, ember-ajax
, ember-network
)。 You would activate the loading state of your component once you click the button/link to load the content, and once the promise is resolved you change the state of your component again. 单击按钮/链接以加载内容后,您将激活组件的加载状态,一旦解决了承诺,您将再次更改组件的状态。
Both ways your component can show its content once it receives the data and you preserve AUDD (Actions Up, Data Down). 一旦接收到数据,组件就可以显示其内容,并保留AUDD(Actions Up,Data Down)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.