如何维护页面状态,以便您可以使用emberjs提供永久链接? [英] How do you maintain the page state, so that you can provide permalinks using emberjs?

查看:101
本文介绍了如何维护页面状态,以便您可以使用emberjs提供永久链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能很好地了解你如何支持固定链接。这可能只是因为emberjs不支持永久链接。

I can't to get a good idea of how you support permalinks. This is perhaps simply because emberjs doesn't support permalinks.

我正在构建一个UI,允许用户选择某些报告,所以在这个时候,这很简单添加一个路由报告,其中包含一个ID,以便URL如下所示:

I'm building a UI that allows users to choose certain reports, so in ember this is easy enough you just add a route 'reports' that takes in an id so the URL looks like this:

#/reports/10/

我需要的是一些额外的参数,也可以存在于该URL中,例如开始和结束日期,度量类型例如

What I need to have is some extra parameters to also be present in that URL for example start and end dates and metric types e.g.

#/reports/10/metric/impressions/start/10-08-2013/end/11-08-2013

所以如果我们将它们粘贴到浏览器中,那么这些参数需要被拾取,重要的是当用户更改那些设置例如通过日期选择器,URL应更新以反映新参数。

So those parameters need to be picked up if I paste them in the browser, AND importantly when the user changes those settings e.g. via a date picker the URL should update to reflect the new parameters.

编辑:

这是一个链接根据下面的答案给一个jsbin的解决方案。 http://jsbin.com/ucanam/703

Here is a link to a jsbin with a solution based on the answer below. http://jsbin.com/ucanam/703

推荐答案

只要把我的2美分投入这个话题。请注意,我正在生产中使用这种方法,它的工作正常。实际上这个问题有两个部分。

Just throwing my 2 cents into this topic. Please note that i am using this approach in production and it works fine. Actually there are 2 parts to this question.

1。我如何拥有多个动态细分?

Mike Grasotti使用嵌套资源描述了一种方法。这种方法有效,但我认为这种方法在这种情况下有点麻烦。

One approach is described by Mike Grasotti using nested resources. This approach works but i think this approach is a little bit cumbersome in this case.

为什么我觉得这很麻烦?

Why do i think it is cumbersome?

路线是一种手段在Ember中单独关注。在这种情况下,我没有看到单独的问题。它看起来像我正在尝试镜像你的URL中的窗体的状态。我认为应该是一种负责形式状态的路线。因此,我建议您查看以下文章,其中介绍如何在每条路由上实现多个动态参数:资源嵌套是启用多个动态段的唯一方法?

Routes are a means to separate concerns in Ember. In this case i do not see separate concerns. It looks to me like you are trying to mirror the state of a form in your URL. I think it should be one route that is responsible for the concern "state of the form". Therefore i recommend to have a look at the following post, in which i describe how to implement multiple dynamic parameters per Route: Is resource nesting the only way to enable multiple dynamic segments?

2。

问题是,在序列化钩子仅在路由输入时使用新模型才被触发。我想你有一些逻辑,处理更改参数开始结束的事件。在这种情况下,我想你不再进入路由。那么如何在这种情况下再次触发序列化钩子来更新URL?我在路由器中处理这样的事件,我正在使用以下代码:

The problem is that the serialize hook is only triggered, when the Route gets entered with a new model. I guess you have some logic in place, that deals with the event of changing the parameters start or end. I suppose that you do not re enter the Route in this case. So how do you trigger the serialize hook in this case again to update the URL? I am handling a event like this in my router and there i am using the following code:

var currentRouteName = this.controllerFor("application").get("currentPath");//the ApplicationController stores the name of the current Route
var url = App.Router.router.generate(currentRouteName);
App.Router.router.updateURL(url);

PS:你可以看看我的制作应用程序 here 即可。这个应用程序显示德国电影院最好的电影。即使您不了解德语,您也可以点击顶部区域中的一个控件,并查看更新的URL。我想这几乎和你想要的一样?

PS: You can have a look at my production app here. This app shows the best movies in cinemas in Germany. Even if you do not know german, you can click on one of the controls in the top area and see the URL getting updated. I guess this is pretty much the same you want?

这篇关于如何维护页面状态,以便您可以使用emberjs提供永久链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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