Ember - 使用相同的模型过渡到相同的路线 [英] Ember - Transition to same route with same model

查看:21
本文介绍了Ember - 使用相同的模型过渡到相同的路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个左树列表,列表中的每个项目都使用不同的模型打开相同的路径.我想要的是,如果我一次又一次地点击同一个项目,我希望路线再次加载.我知道 ember 通常不会以这种方式运行.是否有任何调整来实现这一目标?

I have a left tree list, and each item in the list opens same route with different model. What i want is, if i click on the same item again and again, i want the route to load again. I know ember doesn't normally function this way. Are there any tweaks to achieve this?

更新:左树是父路由.点击左树中的项目时,子路由会加载到其出口中.

Update: Left tree is parent route.On clicking items in left tree, child route is loaded in its outlet.

我左边的树的结构是这样的,

My left tree will be structured like this,

item1(link to bodyRoute1 with model1)item2(链接到带有模型 2 的 bodyRoute1)item3(链接到带有模型 3 的 bodyRoute1)item4(链接到带有模型 1 的 bodyRoute2)...等

推荐答案

我是这样做的,

我在一个对象中维护 currentRouteNamecurrentModelId(唯一标识模型的 id),并且它被注入到所有路由中.它会在任何过渡时更新.

I maintain the currentRouteName and currentModelId(An id to uniquely identify the model) in an object and it is injected in all routes. It gets updated on any transition.

从左树开始的所有转换都经过一个通用函数,在该函数中,我检查转发路由,modelId 是否与当前路由,modelId 相同.如果是这样,我会更改另一个全局注入的属性 refreshSameRoute 的值.这个值在子路由中被观察到,如果它改变 this.refresh() 被调用.

All the transitions from left tree go through a common function, And in that function i check if the forwarding route,modelId is the same as current route,modelId. If so, i change the value of another globally injected property refreshSameRoute. This value is observed in the child routes and if it changes this.refresh() is called.

仍在寻找更好的方法.

这篇关于Ember - 使用相同的模型过渡到相同的路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆