10

Given the following Ember.js application (using Ember 1.0.0.rc.6.1 and Ember Data 0.13):

App = Ember.Application.create({ LOG_TRANSITIONS: true });

App.Store = DS.Store.extend();

App.Router.map(function() {
    this.resource('promotions', function() {
        this.resource('promotion', { path: '/:promotion_id' }, function() {
            this.resource('entrants', function() {
                this.resource('entrant', { path: '/:entrant_id' });
            });
        });
    });
});

App.PromotionRoute = Ember.Route.extend({
    model: function() {
        return { id: 1, name: 'My Promotion' };
    }
});

App.EntrantsIndexRoute = Ember.Route.extend({
    model: function(params) {
        console.warn('EntrantsIndexRoute', '\nparams:', params, '\nparams.promotion_id:', params.promotion_id, '\narguments:', arguments);
        console.log('params should be:', { promotion_id: 1 });
        console.log('The queried URL should be:', '/entrants?promotion_id=1');
        return App.Entrant.find({promotion_id: params.promotion_id});
    }
});

App.Entrant = DS.Model.extend({
    name: DS.attr('string')
});

If you enter the url #/promotions/1/entrants, which should be a nested resource, the params is an empty object. How can I access promotion_id there? JSFiddle here, take a look at the console after clicking on "Click me": http://jsfiddle.net/Kerrick/4GufZ/

4

2 に答える 2

0

このコードを試してください:

App.EntrantsIndexRoute = Ember.Route.extend({
    model: function() {
    var promotion_id = this.modelFor('promotion').query.promotion_id;
    return App.Entrant.find({ promotion_id: promotion_id });
   }
});
于 2013-09-10T03:13:45.673 に答える