admin管理员组

文章数量:1415698

My route is defined:

this.resource("visitor", {path: ":id"});

When I visit the page via the URL /12345, the value of this.currentModel is

{id: "12345"}

but when I this.transitionToRoute("visitor", "12345") from another (parent) controller, the value of this.currentModel is

"12345"

I also get this exception:

Uncaught Error: assertion failed: Path '12345' must be global if no obj is given.

Any ideas what's going on?

More code:

App.VisitorRoute = Ember.Route.extend({
  model: function (params) {
    return {id: params.id};
  },
  setupController: function() { ... }
}

My route is defined:

this.resource("visitor", {path: ":id"});

When I visit the page via the URL /12345, the value of this.currentModel is

{id: "12345"}

but when I this.transitionToRoute("visitor", "12345") from another (parent) controller, the value of this.currentModel is

"12345"

I also get this exception:

Uncaught Error: assertion failed: Path '12345' must be global if no obj is given.

Any ideas what's going on?

More code:

App.VisitorRoute = Ember.Route.extend({
  model: function (params) {
    return {id: params.id};
  },
  setupController: function() { ... }
}
Share Improve this question asked May 29, 2013 at 10:31 SriSri 5,84510 gold badges51 silver badges68 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You need to explain to the router how to translate your model into a URL, for that you need to override serialize.

App.VisitorRoute = Ember.Route.extend({
  model: function (params) {
    return {id: params.id};
  },
  serialize: function(model) {
    return model;  
  }
});

After that pass the model with the transition:

this.transitionToRoute('visitor' , { id: 12345 });

When you call this.transitionToRoute() you need to pass in the route and the model as arguments, so instead of this.transitionToRoute("visitor", "12345"), rather use this.transitionToRoute("visitor", vistorModel)

本文标签: javascriptEmber transitionToRoute and currentModel issueStack Overflow