0

鉴于以下路线:

App.Router.map ->
  @resource 'locations', path: '/:location_id', ->
    @route 'events', path: '/events/:date'

App.LocationsEventsRoute = Ember.Route.extend
  model: (params) ->
    location_id = @modelFor('locations').get('id')
    console.log location_id

访问“/#/gothenburg-se/events/2013-09-03”,location_id返回null. 这在 v1.0 之前有效。发生了什么变化,我该如何解决?

4

1 回答 1

0

这可能是由于 1.0.beta.1 的 Ember 数据发生了变化。您可能想查看过渡文档。

https://github.com/emberjs/data/blob/master/TRANSITION.md

我认为这样的事情适用于您的路线:

App.LocationsEventsRoute = Ember.Route.extend({
  model : function(params){
    // find returns a promise
    var locProm = this.store.find('location',params.location_id);
    // once the promise has resolved you can log the id
    locProm.then(function(loc){
      console.log( loc.get('id') );
    }); 
    // return the promise immediately and let Ember resolve it
    return locProm;
  }
});
于 2013-09-05T06:26:42.850 回答