简体   繁体   English

EmberJS:具有动态段(路由器)的ArrayController,但不是Store

[英]EmberJS: ArrayController with Dynamic Segments (Router) but not Store

i was wondering how I could build a "simple" app for: 我想知道如何构建一个“简单”的应用程序:

/photos/ (shows all photos – via ArrayController but without a remote service)
/photos/1  ... /photos/2  (shows one photo)

Can anyone offer a best practice? 谁能提供最佳实践?

You have to define a route that matches the url you want: 您必须定义与所需网址匹配的路线:

App.Router.map(function() {
    // this will give you ~/#/photos
    this.route('photos') 
    // this will give you ~/#/photos/1 (or whatever number)   
    this.route('photo', { path: '/photos/:photo_id' }); 
});

Here's a sample: http://jsfiddle.net/schawaska/AabL8/ 以下是一个示例: http//jsfiddle.net/schawaska/AabL8/

If you want to do nested views, like displaying a list of thumbs and when clicking the thumb you see the picture in its actual size underneath the list, then you'll have to do it slightly different by using route resources, nested like this: 如果你想做嵌套视图,比如显示一个拇指列表,点击拇指时你会看到列表下面的实际大小的图片,那么你必须使用路由资源稍微不同,嵌套如下:

App.Router.map(function() {    
    this.resrouce('photos', function() {
        this.route('photo', { path: '/:photo_id' });    
    });
});

If you do it this way, you'll have to add an {{outlet}} in the "photos" template and add Photos in the name of the classes that is responsible for a single photo object 如果您这样做,则必须在“照片”模板中添加{{outlet}} ,并在负责单个照片对象的类名称中添加Photos

  • PhotoRoute becomes PhotosPhotoRoute PhotoRoute成为PhotosPhotoRoute
  • data-template-name="photo" becomes data-template-name="photos/photo" data-template-name="photo"变为data-template-name="photos/photo"

Here's a sample: http://jsfiddle.net/schawaska/JfRbf/ 以下是一个示例: http//jsfiddle.net/schawaska/JfRbf/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM