Ember.js - 学习动态路段,link-to,嵌套路线

Ember.js - Learning dynamic segments, link-to, nested routes

我正在尝试学习如何在 Ember 中进行动态细分。我以为我明白了,但显然它不起作用。 我对应的文件结构和模型查询是否正确?

router.js

Router.map(function() {
  this.route('photos', function() {
    this.route('photo', { path: '/:photo_id' }, function() {
      this.route('comments');
      this.route('comment', { path: '/comments/:comment_id' });
    });
  });
});

使用照片模型在应用中某处创建动态 link 列表:

{{#each photos as |photo|}}
  {{#link-to 'photos.photo' photo}}{{photo.name}}{{/link-to}}
{{/each}}

一切都符合我的文件结构吗?

文件结构:

app
├── controllers
|   └── photo
|   |   └── comment
|   |   |   └── index.js
|   |   ├── index.js
|   |   └── comments.js
|   └── photos.js
├── routes
|   └── photo
|   |   └── comment
|   |   |   └── index.js
|   |   ├── index.js
|   |   └── comments.js
|   └── photos.js
└── templates
|   └── photo
|   |   └── comment
|   |   |   └── index.hbs
|   |   ├── index.hbs
|   |   └── comments.hbs
|   └── photos.hbs
└── router.js

routes/photos.js

model() {
  return this.store.findAll('photo');
}

假设我想显示所有带评论的照片,我可以得到下面的模型。

routes/photo/index.js

model(params) {
  return this.store.findRecord('photo', params.photo_id, {include: 'comments'});
}

不确定接下来的 2 个模型。

routes/photo/comments.js

model(params) {
  return this.store.query('comment', { photo: photo_id })
}

routes/photo/comment/index.js

model(params) {
  return this.store.findRecord('comment', params.comment_id);
}

文件结构应反映 router.js 文件中的内容。我只展示了路由层次结构,它适用于控制器和模板。

app/routes/photos.js
app/routes/photos/index.js
app/routes/photos/photo.js
app/routes/photos/照片/comments.js

您缺少 photos 文件夹。参考这个 alexspeller diagonal