从Ember Pre1到Pre4:每条路线有多个动态网段?更新:动态段允许使用什么语法? [英] From Ember Pre1 to Pre4: Multiple dynamic segments per route? Update: What is the allowed syntax for dynamic segments?

查看:56
本文介绍了从Ember Pre1到Pre4:每条路线有多个动态网段?更新:动态段允许使用什么语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试将基于pre1的Ember迁移到当前版本pre4。在我的pre1代码中,我定义了一条路由,如下所示:

I am currently trying to migrate my Ember based on pre1 to the current release pre4. In my pre1-code, i defined a route as follows:

formCreated : Ember.Route.extend({
        route : '/genre=:genre/sorting=:sorting/location=:location/range=:range/time=:date/:timeFrame',
....
})

这条路线对我来说效果很好,但是现在我正在用pre4来模仿这种行为。这是我的方法:

This Route worked fine for me, but now i am struggling to mimic this behaviour with pre4. This is my approach:

App.Router.map(function() {
  this.route("/");
  this.route("formCreated", { path: "/genre=:genre/sorting=:sorting/location=:location/range=:range/time=:date/:timeFrame" });
});
App.FormCreatedRoute = Ember.Route.extend({
  serialize: function(context, params){
    // here i am returning a hash containing all the dynamic segments
  }
});

出了什么问题?
当应用程序进入状态,则网址无法正确更新。我看到的结果是:

What is going wrong? When the App enters the state, the URL does not get updated properly. I am seeing this result:


/ genre =:genre / sorting =:sorting / location =:location / range =: range / time =:date / 6:00-19:00

所以我的大部分动态细分都无法获得更新。我确保我的自定义序列化方法返回一个适当的哈希对象,其中为每个动态段设置了一个属性。

So most of my dynamic segments do not get updated. I made sure that my custom serialize method is returning an appropriate hash object, where one property for each dynamic segment is set.

每条路线仍有多个动态段可能使用pre4,还是我必须切换到某些路由嵌套方法或类似方法?

更新:找到根本原因:
我刚刚发现错误是由于我使用该路由的语法而发生的。我将其更改为以下内容(用 /替换了 =):

UPDATE: Root cause found: I just discovered that the error happened because of the syntax i used for the route. I changed it to the following(replaced the "=" with "/"):

this.route("formCreated", { path: "/genre/:genre/sorting/:sorting/location/:location/range/:range/time/:date/:timeFrame" });

是否存在有关如何构建路径的文档?自ember-pre1以来,该语法已更改。我想拥有一个用户友好的URL,并且许多斜杠使阅读变得困难。还是规则,就是一个段始终必须以:/开头?

Is there any documentation on how the path may be structured? It seems that syntax has changed since ember-pre1. I would like to have a user friendly URL and those numerous Slashes make it difficult to read. Or is the rule, that a segment always has to start with ":/"?

推荐答案

您将需要使用资源嵌套,如此处此处

You will need to use resource nesting, like described here and here

App.Router.map(function() {
    this.route('/');
    this.resource('genre', { path: '/genre/:genre_id' }, function(params) {
        this.resource('sorting', { path: '/sorting/:sorting_id' }, function(params) {
            ...
        });
     });
});

这篇关于从Ember Pre1到Pre4:每条路线有多个动态网段?更新:动态段允许使用什么语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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