0

如果我在 ember.js 中有一个名为“:albumid”的动态段的路由,我如何从视图中访问它?

Ember.Route.extend({
    route: "/:albumid"
})

参数设置如下:

gotoAlbum = function(r,e) {
    router.transitionTo("album", {albumid: StuffThatReturnsTheAlbumid});
}
4

1 回答 1

-1

You'll need to use the albumid param in the deserialize() method of your route to return a context object. This context will be passed into connectOutlets() for your route. Within connectOutlets() you can pass the context along to the controller and/or view.

In the example below, an AlbumController will be created in which its content property is set to be the context passed into connectOutlets(). An AlbumView will also be created, which will have access to the controller's content:

Ember.Route.extend({
  route: "/:albumid",

  serialize: function(router, context){
    return {albumid: context.get('albumid')};
  },

  deserialize: function(router, params){
    // return a context object that will be passed into connectOutlets()
    return App.store.find(App.Album, params.albumid);
  },

  connectOutlets: function(router, context) {
    // context comes from deserialize(), and will be passed in as the
    // content property for AlbumController
    router.get('albumsController').connectOutlet('album', context);
  }
})
于 2012-09-14T16:21:42.387 回答