如何在EmberJS中导航到嵌套资源的路径?

时间:2014-06-20 22:56:06

标签: ember.js

说我有这个设置:

App.Router.map(function() {
  this.resource("people", {path: "people/:person_id"} function() {
    this.resource("male", {path: "male"}, function() {
      this.resource("clothingCollection", {collection/:collection_id}, function() {
        this.route("item", {path: "item/:item_id"});
      });
    });
    this.resource("female", {path: "female"}, function() {
      this.resource("clothingCollection", {collection/:collection_id}, function() {
        this.route("item", {path: "item/:item_id"});
      });
    });
  });
});

如何导航到people / female / x / clothingCollection / y / item / z?

1 个答案:

答案 0 :(得分:0)

这取决于你在哪里。资源名称必须是唯一的。

Why do nested resource routes reset the namespace in Ember?

App.Router.map(function() {
  this.resource("people", {path: "people/:person_id"} function() {
    this.resource("male", {path: "male"}, function() {
      this.resource("maleClothingCollection", {collection/:collection_id}, function() {
        this.route("item", {path: "item/:item_id"});
      });
    });
    this.resource("female", {path: "female"}, function() {
      this.resource("femaleClothingCollection", {collection/:collection_id}, function() {
        this.route("item", {path: "item/:item_id"});
      });
    });
  });
});

我建议将其更改为以下内容:

人力资源

来自模板

{{#link-to 'clothingCollection.item' model}}Go there{{/link-to}}

从路线

this.transitionTo('clothingCollection.item', model);

来自控制器

this.transitionToRoute('clothingCollection.item', model);

人力资源之外

来自模板

{{#link-to 'clothingCollection.item' person item}}Go there{{/link-to}}

从路线

this.transitionTo('clothingCollection.item', person, item);

来自控制器

this.transitionToRoute('clothingCollection.item', person, item);