model对于父路径,以前停止工作

时间:2013-09-03 08:29:48

标签: ember.js

考虑以下路线:

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之前有效。改变了什么,我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这可能是由于1.0.beta.1的Ember Data的变化。您可能想查看转换文档。

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;
  }
});