0

I'm attempting to build a github issue tracker with ember and ember data. The github API is accessed via a node server (and works fine), but I'm having issues trying to use ember's dynamic segments and I'm not sure of the best way to structure my routes & models.

How should I structure my routes and models if I want the url to be /user/repo/issue?

I've tried all different combinations of dynamic segments and resources/routes...

this.resource('user', {path: ':user'}, function(){
  this.resource('repo', {path: ':repo'}, function(){
    this.resource('issue', {path: ':issue_id'});
  });
}); // 1

this.resource('repo', {path: ':userAndRepo'}, function(){
  this.resource('issue', {path: ':issue_id'});
}); // 2

this.resource('repo', {path: ':userAndRepo'});
this.resource('issue', {path: ':userAndRepo/:issue_id'}); //3

But I can't seem to get it working smoothly. I'm tearing my beard out trying to understand it.

The closest I got was having a combined segment for :userAndRepo, but for any link-to's I had in my issues template, I had to explicitly set that model on the IssuesController so that my link-to was {{#link-to 'issues' userAndRepo issue}} Also, my API was getting hit every time I moved from the child issue route back into the parent repo route.

Any ideas or suggestions would be greatly appreciated. Apologies if I haven't explained myself very well.

4

1 回答 1

0

1 号是正确的实现。这是一个包含嵌套资源的简单示例(我很懒,只是使用了 pojos,但您可以看到模型钩子何时被击中)。

http://emberjs.jsbin.com/EWogUdE/36/edit

http://emberjs.jsbin.com/EWogUdE/36#/

 App.Router.map(function () {
   this.resource('people', function(){
     this.resource('person', {path:':name'}, function(){
       this.resource('dog', {path:':dogname'});
     });
   });
 });
于 2013-10-06T04:30:58.603 回答